- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL Error - #1046 - No database selected
The error-#1046 can occur when we are creating a table, but forget to select the database. Let us say we have started MySQL as shown below −
After giving the correct password, the above window will open. Now create a table without choosing any database. This will show an error −
mysql> CREATE table TblUni -> ( -> id int, -> Name varchar(100) -> );
ERROR 1046 (3D000): No database selected
The following screenshot is showing the same error −
Now, choose any database to get rid of the above error. Firstly, let us check how many databases are present in MySQL with the help of SHOW command −
mysql> SHOW databases;
The following is the output −
+--------------------+ | Database | +--------------------+ | business | | hello | | information_schema | | mybusiness | | mysql | | performance_schema | | sample | | sys | | test | +--------------------+ 9 rows in set (0.00 sec)
Now, we can choose any database. Suppose I am using the database ‘business’, therefore we can choose with the help of ‘use’ command.
mysql> use business; Database changed
After using database ‘business’, we can create the above table and we will not get any error.
mysql> CREATE table TblUni -> ( -> id int, -> Name varchar(100) -> ); Query OK, 0 rows affected (0.50 sec)