/    /  MySQL – List Database

MySQL – List Database

 

When you connect to a MySQL server using the MySQL client, you can run the SHOW DATABASES command to obtain a list of the MySQL databases.

Enter your MySQL password when prompted and access the MySQL server using the following command:

mysql -u user -p

The following command should be executed from within the MySQL shell:

SHOW DATABASES;

In order to list all the databases on the MySQL server, you must be logged in as a user who can access all databases, which is by default the MySQL root user, or set a global privilege called SHOW DATABASES.

MySQL - List Database

Filtering the Result 

By using the LIKE clause, you can filter the output of SHOW DATABASES based on a particular pattern.

Syntax:

SHOW DATABASES LIKE pattern;

The following statement will return all databases with names beginning with the letter ‘Demo’, for example:

SHOW DATABASES LIKE 'emp%';