MySQL is the most popular open source relational database management systems. This tutorial describes how to display all MySQL or MariaDB database server via the command line.
Display MySQL database
The most common way to obtain a list of MySQL database is to use the mysql
client to connect to MySQL server and run the SHOW DATABASES
command.
Use the following command to access the MySQL server, MySQL user and enter your password when prompted:
mysql -u user -p
If you have not set a password for the MySQL user, you can omit the
-p
switch.
Execute the following command in the MySQL shell:
SHOW DATABASES;
This command will print a list of all database users have rights. The output will look like this:
+--------------------+
| Database |
+--------------------+
| information_schema |
| opencart |
+--------------------+
2 rows in set (0.00 sec)
SHOW SCHEMAS
Is another command can be used to list the database, it is SHOW DATABASES
synonymous with the command:
SHOW SCHEMAS;
Using the output SHOW DATABASES
to output the same when the command:
+--------------------+
| Database |
+--------------------+
| information_schema |
| opencart |
+--------------------+
2 rows in set (0.00 sec)
Display all MySQL database
To list all the databases on the MySQL server, you need to have access to all the database as a user login, root user by default is to have permission to view all databases. It can be used SHOW DATABASES
to list all the databases.
Logged in as root MySQL:
mysql -u root -p
Run SHOW DATABASES
the command:
SHOW DATABASES;
You will see a list of all databases on the MySQL server:
+--------------------+
| Databases |
+--------------------+
| information_schema |
| database_name |
| mysql |
| opencart |
| wordpress |
| performance_schema |
| sys |
+--------------------+
7 rows in set (0.00 sec)
Filter results
If the output of the filter in accordance with a command according to a specific mode, the operation SHOW DATABASES
using the time LIKE
clause.
SHOW DATABASES LIKE pattern;
For example, the following statement will return the name to "open" the beginning of all databases:
SHOW DATABASES LIKE 'open%';
+--------------------+
| Database |
+--------------------+
| opencart |
+--------------------+
1 rows in set (0.00 sec)
Percent sign (
%
) represents zero, one, or more characters.
If you want a more sophisticated searches from information_schema
the database schemata
according to the conditions lookup table.
The following statement will provide you with a list of all databases in order to "open" or "word" starting with:
SELECT schema_name
FROM information_schema.schemata
WHERE schema_name LIKE 'open%' OR
schema_name LIKE 'word%';
+--------------------+
| Database |
+--------------------+
| opencart |
| wordpress |
+--------------------+
2 rows in set (0.00 sec)
Display MySQL database from the command line
To obtain a list of databases in MySQL shell without logging in, you can use the mysql
command with the -e
option (on behalf execute), it can also be used mysqlshow
to display database and table information command.
When you want to use the shell script uses MySQL database, which is particularly useful.
Run the following command in the terminal to display a list of all databases:
mysql -u user -p -e 'show databases;'
+--------------------+
| Database |
+--------------------+
| information_schema |
| opencart |
+--------------------+
The following is an mysqlshow
example command:
mysqlshow -u user -p
The output will be the same on a command output.
If you want to filter the output, you can use the grep command.
in conclusion
You have learned how to obtain a list of all MySQL server databases.