[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;


















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap