Managing MySQL on VPS is crucial for users ranging from web developers to system administrators. Knowing how to view a complete list of databases in MySQL on VPS helps you organize, audit, and manage your databases effectively. This guide walks through multiple ways to list all databases, covering both basic and advanced techniques tailored for VPS environments.

MySQL on VPS is a versatile relational database management system (RDBMS) known for its excellent performance and scalability. When hosted on a Voxfor VPS, it provides greater flexibility and customization compared to shared hosting solutions.
Using MySQL on VPS provides an isolated environment with dedicated resources and more control over security settings and performance. This characteristic makes VPS hosting ideal for database-intensive applications. This guide explores several ways to list all databases in MySQL on a VPS, including command-line operations, advanced SQL queries, and graphical tools.
To work with MySQL on VPS, you’ll first need to access your server and verify MySQL installation.
Enter the SSH command with your VPS’s IP address:
ssh user@your_vps_ip

Once connected, check if MySQL is installed:
mysql --version

Update the Package List:
sudo apt update

sudo apt install mysql-server

sudo systemctl start mysql

sudo systemctl enable mysql

sudo mysql_secure_installation


mysql --version

sudo systemctl status mysql

Note: This guide assumes MySQL is installed on Ubuntu. If using other operating systems, see the sections below.
Update the Package Repository:
sudo yum update # For CentOS/RHEL 7 and earlier
sudo dnf update # For CentOS/RHEL 8 and later
sudo yum install mysql-server
sudo dnf install @mysql
sudo systemctl start mysqld
sudo systemctl enable mysqld
sudo mysql_secure_installation
mysql --version
You’re now ready to access MySQL and start listing databases.
The simplest way to list databases in MySQL on VPS is by using the SHOW DATABASES command.
Log in to MySQL on VPS from your terminal:
mysql -u root -p
Enter your MySQL root password.

Then, Run:
SHOW DATABASES;

This command outputs a list of all databases on the MySQL server.
If permission errors occur, it may be due to limited user access. Logging in as the root user or an admin with full permissions should resolve this.
For a deeper look into your databases, you can query specific tables within MySQL’s information_schema.
The INFORMATION_SCHEMA database contains metadata about all databases on the server:
SELECT schema_name AS Database
FROM information_schema.schemata;

This query provides a list similar to SHOW DATABASES, with options for customization.
You can filter results, for example, to list databases with a specific prefix:
SELECT schema_name
FROM information_schema.schemata
WHERE schema_name LIKE 'test_%';

This query shows only databases starting with test_, allowing you to focus on specific databases.
MySQL Workbench is a user-friendly graphical tool designed to make managing MySQL databases easier. For those who prefer a GUI, it provides an intuitive interface for efficient database management.
A sidebar in Workbench displays the available database. Such a feature simplifies database navigation and management.
Securing MySQL databases on a VPS is critical for data safety. Since the root user has extensive privileges, it’s wise to create restricted users for specific tasks.
Sign in to MySQL using the root user account.
CREATE USER 'limited_user'@'%' IDENTIFIED BY 'password';

GRANT SELECT ON database_name.* TO 'limited_user'@'%';

FLUSH PRIVILEGES;

Using restricted users helps reduce accidental changes and increase security.
For regular tasks, such as listing databases, automation can simplify management.
Open a new file, for example, list_databases.sh:
nano list_databases.sh

#!/bin/bash
mysql -u root -p -e "SHOW DATABASES;"

chmod +x list_databases.sh

./list_databases.sh
To automate the script with cron:
Open the crontab editor:
crontab -e

Add a new job to run the script daily:
0 2 * * * /path_to_script/list_databases.sh

This setup will run the database listing script daily at 2 AM.
When managing MySQL databases on a VPS, you may face some common issues.
For errors like Access denied for the user, verify:
The user has proper permissions:
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
If remote connection issues arise:
If MySQL is down, start it with:
sudo systemctl start mysql

Check server status and logs for further troubleshooting:
sudo systemctl status mysql

To keep databases safe and efficient, follow these best practices:
Backups prevent data loss. Automate backups with mysqldump:
mysqldump -u root -p --all-databases > /path_to_backup/all_databases.sql
Regularly update MySQL and your server for the latest security patches. Use strong passwords and review access controls.
Monitoring tools can track MySQL performance and resource usage, helping you identify issues before they impact applications.
Listing all MySQL databases on a VPS is a fundamental skill, beneficial for both database administration and development. From the basic SHOW DATABASES command to advanced queries and automation, this guide has provided several methods suited for a VPS environment. These techniques can be used with regular practice and should help you manage your databases confidently and improve your overall MySQL experience on a VPS.

Vinayak Baranwal wrote this article. Use the provided link to connect with Vinayak on LinkedIn for more insightful content or collaboration opportunities.