[Fix] MySQL No database selected - ERROR 1046 (3D000)

mysql> select * from mytable;

ERROR 1046 (3D000): No database selected
mysql error - no database selected - 1046 3D000

If you are trying to run mySQL query in mysql prompt in console and you get "No SQL selected" then you first need to select the database,

You can know the list of databases that are available, you can make use of show databases;

mysql> show databases;
| Database           |
| information_schema |
| mydb               |
| mysql              |
| performance_schema |
| sys                |
5 rows in set (0.00 sec)

You can select you database using command set database database-name

mysql> use mydb;
Database changed

Now you can run the your query and you should not get 1046 error,

mysql> select * from mytable;
| name | address     | city    |
| Sam  | 101, ABC ZY | Chicago |
1 row in set (0.00 sec)

Note: You can also run the command using {datbasename}.{table name} as well!

Example: mysql> select * from mydb.mytable;
Try Out Code2care Dev Tools:


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.