How To List MySQL / MariaDB Database? – POFTUT

How To List MySQL / MariaDB Database?


MySQL is a very popular opensource database. MySQL is created by MySQL AB a Swedish company and then bought by Sun. Sun is bought by Oracle and MySQL is currently owned by Oracle. MySQL is very popular in the opensource community. In this post, we will look at how to list databases in MySQL.

Check MySQL Service Status

We need to be sure that MySQL daemon is running we will check with following systemctl command. The MySQL service name is the same mysql.

$ systemctl status mysql
Check MySQL Service Status
Check MySQL Service Status

Connect MySQL Server

We will use MySQL server tools to connect MySQL daemon. mysql is the most used command-line tool to connect and manage a MySQL server. We will connect server by running mysql command with sudo which means with root privileges.

$ sudo mysql -u root
Connect MySQL Server
Connect MySQL Server

Another way to connect MySQL daemon is by providing a password with -p parameter

$ sudo mysql -u root -p
Connect MySQL Server
Connect MySQL Server

MySQL List/Show  Databases

We will usage MySQL command show databases to list databases. Using semicolon at the end of the command is important otherwise the command will fail.

mysql> show databases;
MySQL List/Show  Databases
MySQL List/Show  Databases

List Databases From Bash without Entering MySQL Shell

We can list MySQL databases without entering the MySQL tool command line through bash. We will use a similar command to connect MySQL database but providing show database command as a parameter. We will use MySQL show databases.

$ sudo mysql -u root -e 'show databases;'
List Databases From Bash without Entering MySQL Shell
List Databases From Bash without Entering MySQL Shell

We have issued MySQL command with -e parameter. show databases; runs as a MySQL connect in the MySQL shell.

$ sudo mysql -u root -h 192.168.122.211   -e 'show databases;'

Here is everything is similar to the previous example except hostname which is provided as -h 192.168.122.211We provide hostname as the remote host, not localhost. To connect remote host firewall must give access to the port and MySQL daemon should be listening specified IP’s interface.

LEARN MORE  Php Tutorial

2 thoughts on “How To List MySQL / MariaDB Database?”

Leave a Comment