When working with Linux-based hosting environments, managing databases via the command line is a crucial skill — especially if you’re running a virtual server or dedicated server without a graphical interface. In this guide, we’ll walk you through how to list all MySQL databases using the terminal. Whether you’re an experienced sysadmin or a website owner learning the ropes, this article has you covered.
Before diving into the commands, let’s quickly cover a few scenarios where this command is useful:
Now let’s move to the actual commands.
To interact with MySQL via the command line, first log in to the MySQL shell:
mysql -u root -p
💡 Tip: If your MySQL root user doesn’t have a password set (not recommended for production), you can skip -p.
Once you’re inside the MySQL shell, simply run:
SHOW DATABASES;
You’ll see output similar to:
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | your_database_name | +--------------------+
Each row represents a database stored on the MySQL server. Some of these (like information_schema, performance_schema) are system databases and should not be modified.
If you prefer to list databases directly from the shell without opening the MySQL prompt, use:
mysql -u root -p -e 'SHOW DATABASES;'
This is useful for scripting and automation tasks.
To filter output and find specific database names, you can combine the command with grep:
mysql -u root -p -e 'SHOW DATABASES;' | grep your_keyword
Replace your_keyword with part of the database name. This trick is handy when managing multiple clients or applications.
If you’re curious about physical storage, MySQL databases are typically stored in:
/var/lib/mysql/
Each folder inside corresponds to a database name. Do not modify or delete anything here manually unless you know exactly what you’re doing — always use SQL commands or admin tools.
sudo systemctl status mysql
sudo apt install mysql-client
To list MySQL databases via the command line on Linux:
This method is fast, secure, and works perfectly in SSH environments — exactly what you need for effective server and database management.