How to Show All Databases in MySQL Quickly
To show all databases in MySQL, use the
SHOW DATABASES; command. This lists every database your MySQL server manages.Syntax
The command to list all databases is simple and looks like this:
SHOW DATABASES;: Lists all databases accessible to your MySQL user.
mysql
SHOW DATABASES;
Example
This example shows how to connect to MySQL and list all databases available to your user.
mysql
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)
Output
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
Common Pitfalls
Some common mistakes when trying to list databases include:
- Not having the right permissions to see all databases, which results in an empty or partial list.
- Forgetting the semicolon
;at the end of the command, causing a syntax error. - Trying to use
SHOW DATABASESwithout connecting to the MySQL server first.
mysql
/* Wrong: Missing semicolon */ SHOW DATABASES /* Correct: Include semicolon */ SHOW DATABASES;
Quick Reference
Remember these tips when listing databases:
- Always connect to MySQL before running commands.
- Use
SHOW DATABASES;to list databases. - Check your user permissions if you see fewer databases than expected.
Key Takeaways
Use
SHOW DATABASES; to list all databases in MySQL.Ensure you have proper permissions to see all databases.
Always end MySQL commands with a semicolon
;.Connect to the MySQL server before running commands.
If databases don't show up, check your user privileges.