MySQL is a free and open-source relational database management system. While working with MySQL databases you often need to perform tasks such as creating and managing tables, displaying MySQL databases, etc.
In this article, we will discuss how to show database in MySQL. Here I will be using Ubuntu 20.04 with MySQL installed on it.
You can follow how to install MySQL in Ubuntu if you want to install MySQL on your system.
You should have MySQL installed on your system
You should have access to a user account with superuser privileges to execute the MySQL command.
Login to MySQL on your system
Before you run any SQL commands in MySQL you need to log in as the root user or you should have superuser privileges. Use the given command in your Linux terminal to login into the MySQL server.
sudo mysql -u root -p
This will ask you to enter the root password, enter it to proceed.
How to show MySQL databases
To display the list of databases you created or that exist on your system, use the given command in MySQL prompt-
The output of this command will look something like the one given below.
Alternatively, you can use –
This command will produce the same result as the previous command does.
You can combine this command with the command we used to login into the MySQL server. This will immediately display the result in the Linux command line. The full command is given below.
mysql -u user -p -e 'show databases;'
Now you can see the output in the given image.
Display customized output of MySQL databases
You can show the filtered output of the
show databases; command by using the LIKE clause. The syntax of using the LIKE clause is given below.
SHOW DATABASES LIKE pattern;
For example –
SHOW DATABASE LIKE '%employee%';
This will display the list of databases that contains the ’employee’ string in it. Use
% is a wild card character that represents one or more characters.
This is how you can display the databases in MySQL on a Linux system. Now if you have a query then leave it in the comments below.