In this article, we will see how to get list of databases in MySQL. We can get list of databases in MySQL server using SHOW command. The SHOW SCHEMAS command is a synonym for SHOW DATABASES.
Syntax:
SHOW {DATABASES | SCHEMAS} [LIKE 'pattern' | WHERE expr];
Get list of databases in MySQL
1. Connect to the MySQL using below connection string.
mysql -u root -p
2. Get the list of all MySQL databases.
SHOW DATABASES;
3. SHOW SCHEMAS will also prints the same as above output.
SHOW SCHEMAS;
Filtering Databases:
4. Get the list of database whose name ends with ‘schema’.
SHOW DATABASES WHERE `DATABASE` LIKE '%schema';
5.Filter the databases whose name ends with ‘schema’.
SHOW DATABASES WHERE `DATABASE` NOT LIKE '%schema';