How To List MySQL/MariaDB Databases
I have some MySQL databases. I have no previous experience about MySQL. How can list existing databases with bash?MySQL and MariaDB are using same code base and tools. So we can use following instructions to list MariaDB too.
Check Database Service
First be sure MySQL/MariaDB service is running
$ systemctl status mysql
As we can see from
systemctl output the database service is working properly.
Login To MySQL Interactive Shell
In order to list databases we need to connect and login MySQL interactive shell. We will use
mysql tool by providing the user
$ mysql -u root
Now we will use
show databases command to list existing databases.
; is important which means end of the command.
> show databases;
We cab see that there is 5 databases in this MySQL Server.
List Without Entering MySQL Shell
Entering MySQL database server and running
show database command may a trivial task. We can directly run
show database command from the Linux bash shell like below by using
$ sudo mysql -u root -e "show databases;"
List Without Entering MySQL Shell From Remote Database Server
If we want to list databases from a remote database server we need to provide the remote system host name or IP address. In this example we will use
-h option which is short form of
host. We will connect remote server `192.168.142.144
$ mysql -u root -h 192.168.142.144 -e "show databases;"