[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;
Advertisements
Try Out Code2care Dev Tools:

Advertisements



#Android #Java #Linux #Microsoft #Google #Python #MacOS #Notepad++ #Microsoft Teams #CSS #PHP #SharePoint #Html #Linux #C-Program #Bootstrap #jQuery #Sublime #Android-Studio #Facebook #Eclipse #WhatsApp #News #MySQL #Json #HowTos #JavaScript #FTP #S3


Advertisements


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 Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency