MySQL SHOW DATABASES Command
The SHOW DATABASES
command in MySQL is used to list all the databases available on the MySQL server. It helps you to view the existing databases and ensure their availability.
Syntax
Key Points
Access Control:
- The list of databases displayed depends on the privileges of the connected MySQL user.
- A user can only see databases for which they have access.
Default Databases:
information_schema
: Stores metadata about all other databases.mysql
: Contains MySQL system tables.performance_schema
: Contains information about server performance.sys
: Provides views and functions to simplify server performance monitoring.
Examples
1. List All Databases
Example Output:
2. Filter Databases Using LIKE
To list databases with a specific pattern, use the LIKE
clause:
Example Output:
3. Filter Databases Using WHERE (Information Schema)
If you need advanced filtering, query the SCHEMATA
table in the information_schema
database:
Example Output:
Checking Database Details
1. Show the Default Character Set and Collation
To check the character set and collation of each database:
2. Use a Specific Database
To start working with a specific database:
3. Drop a Database
To delete a database:
⚠️ Warning: Dropping a database deletes all its data permanently.
Privileges Required
To use SHOW DATABASES
, the user must have the SHOW DATABASES
privilege or some privilege on a database.
Troubleshooting
1. No Databases Listed
- Ensure you are logged in with a user that has sufficient privileges.
- Example:
2. Access Denied Error
- Grant appropriate permissions:
Practical Use Case
- Quickly check if a database exists on the server.
- Verify the list of databases accessible to the current user.
- Troubleshoot connectivity or permissions issues by comparing visible databases for different users.
Let me know if you need additional guidance!