- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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)
- Error 1046 No database Selected, how to resolve?
- Fix MySQL Database Error #1064?
- How to check which database is selected in MySQL?
- Resolve Unknown database in JDBC error with Java-MySQL?
- Fix ERROR 1064 (42000) while creating a database in MySQL?
- No error while inserting record in child table with no match in master table in SAP
- Order by selected record in MySQL?
- Display first selected row in MySQL?
- MYSQL - select database?
- Display multiple selected rows using MySQL IN()
- How can we get only the name having no other details about the tables in MySQL database?
- Get the size of selected rows in MySQL
- How to deal with error “undefined columns selected” while subsetting data in R?
- When the MySQL delimiter error occur?
- Declare syntax error in MySQL Workbench?