mysql> select * from mytable;
ERROR 1046 (3D000): No database selected

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;Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!