MySQL is an RDMS where data is stored in a related manner by using tables. Multiple databases consist of multiple tables. MySQL databases can be listed in different ways by using a command-line interface or GUI tools. In this tutorial, we examine how to list or show MySQL databases via the command-line interface.
Login MySQL Shell
The first step is to list MySQL databases is logging in to the MySQL interactive shell. MySQL interactive shell provides MySQL-specific command-line interface for different operations. The mysql
command is used to log in to the MySQL shell. Also, the -u
option is used to specify the MySQL username which is generally root
. The -p
option is specified for the login with a password.
$ mysql -u root -p

List MySQL Databases
The MySQL command-line interface provides the show databases
command in order to show or list currently existing databases. The ;
sign is added at the end of the command. The databases are listed line by line.
mysql> show databases;

Select MySQL Database
In order to run an SQL or query in a database, the data should be selected by using the use
command. In the following example, we select the database named sys
.
mysql> use sys;
Show Tables
After selecting a database we can also list or show tables about the selected database. The show tables;
command can be used to list tables for the selected database.
mysql> show tables;
