Show (List) MySQL Databases via Command Line on Linux
Introduction
This article explains how to list your MariaDB or MySQL databases, a fundamental skill for anyone working with MariaDB or MySQL. These instructions apply to both MariaDB and MySQL servers because MariaDB is a drop-in replacement for MySQL.
Listing your MySQL databases offers several key advantages, empowering you to better manage your data. Quickly seeing your list of databases can help you verify if the database you just created exists and is accessible. Reviewing your list of databases can help pinpoint whether the database itself is missing or if the issue lies elsewhere when troubleshooting database connection problems or data discrepancies.
Prerequisites
- Root access.
- MariaDB or MySQL installed. This process works the same on essentially all major Linux distributions.
Login to MariaDB / MySQL to List Databases
-p tells MariaDB/MySQL to prompt you for the password.
- Log into the database server from the command line using the command below:
mysql -u root -p - Enter the root (or other database user) password when prompted.
- Verify your prompt after logging in, you should see one of the below prompts:
- For MariaDB:
MariaDB [(none)]> - For MySQL:
mysql>
- For MariaDB:
- Show all databases by running the following command. (The same command works on both MariaDB and MySQL, producing similar results.)
SHOW DATABASES;
Example output:mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
On some Linux distributions, MariaDB replaces MySQL entirely — running `mysql` in the terminal will still launch the MariaDB client.
Related Articles and Next Steps
- Want to create a new database? Check out our tutorial: Create a MySQL Database on Linux via Command Line.
- To select a database for troubleshooting or to manipulate the data, see: Selecting a MySQL Database
Delete a database by following the instructions found here: Deleting a MySQL Database | Liquid Web