[FIX] MySQL ERROR 1046 (3D000) No Database Selected

This article is a step by step guide to resolve “MySQL ERROR 1046 (3D000) No Database Selected” error. If you are a DBA or a developer, this post will help you fix this MySQL 1046 error.

If you are getting this error message means you are trying to execute MySQL queries statement using MySQL command prompt. Let’s go through why we get the error 1046 (3D000) followed by the step by step procedure to resolve this error.

Why you are getting 1046 (3D000): No database selected Error?

MySQL ERROR 1046 (3D000) No Database Selected

Let me tell you first why you are getting this 1046 MySQL error message.  You might have guessed it right by now; the error message is pretty clear that you have not selected the database before executing your MySQL statement.

This error generally occurs when you try to create Table in MySQL database using command prompt.

Because while executing command from command prompt you need to select the database also since the MySQL will not be able to know for which database you are executing the script..

When you execute create table statement from MySQL workbench then at that time you need to manually select the database then you execute your statement. Similarly, while executing a script from command prompt screen, make sure you have provided the database name.

The next question is “how to provide database name?” No worries. Here are the steps; just follow the below steps by step procedure to get rid of the error.

Steps to resolve MySQL ERROR 1046 (3D000) No Database Selected:

Step 1:

  • Open MySQL command prompt.
  • Go to start menu and open MySQL Command Line Client.
MySQL command line client

Step 2: Select the database

If you know the database name:

  • Select the Database on which you want to execute your script.
  • If you know the name of database, then enter the database name in following format.

use <database_name>;

select and use a database in MySQL

Note: Don’t skip this step, this is solution to get rid of the 1046 (3D000) error message.

If you do not know the database name:

If you don’t know the available database names or the database on which you are going to execute the script, then you can list all available databases using following command.

SHOW databases;

Show database command lists down all the databases available. Then you run use <database_name>;

Show database in MySQL

Step 3: Execute statement

Once database is selected, you can execute your required SQL statement. Here we will execute create table statement in the database as an example.

mysql create table no database selected fix - table created

That’s it. You can see the created table in the MySQL database using MySQL workbench.

Table created in MySQL


Is it not simple? I hope you now know the reason behind “MySQL error 1046 No Database selected error” issue and how to fix it. Do share your feedback if this post helped you to fix the MySQL 1046 (3D000) error using above steps in the comment section.

Cheers !!!

Leave a Comment

Your email address will not be published.

Scroll to Top