MySQL 1046: No database selected.

When encountering the error "1046: No database selected" in MySQL, the immediate action to take is to ensure that you have explicitly selected a database to work with. You can do this by running the following SQL command:

USE yourdatabasename;

Replace `yourdatabasename` with the name of your database. If you're unsure of the database name, you can list all databases by running:

SHOW DATABASES;

After selecting the database with the `USE` command, you can proceed with your original query or command that resulted in the error.

Master

MySQL

in Minutes — Grab the Ultimate Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Real-world configs/examples
Handy troubleshooting shortcuts
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the cheatsheet on your email!
Oops! Something went wrong while submitting the form.

MySQL

Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the cheatsheet on your email!
Oops! Something went wrong while submitting the form.

MORE ISSUES

Made with ❤️ in Bangalore & San Francisco 🏢

Doctor Droid