- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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)
- Related Articles
- 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?
- Order by selected record in MySQL?
- Display first selected row in MySQL?
- How to deal with error “undefined columns selected” while subsetting data in R?
- No error while inserting record in child table with no match in master table in SAP
- How can we get only the name having no other details about the tables in MySQL database?
- Display multiple selected rows using MySQL IN()
- How to deal with error “undefined columns selected when subsetting data frame” in R?
- MYSQL - select database?
- Get the size of selected rows in MySQL
- Declare syntax error in MySQL Workbench?
