List all MySQL databases from Linux command line

Is it possible to get databases details from server command line?

Yeah!! if there is a way to list and sort out the database details from server CLI (command line interface), it’ll speedup your troubleshooting procedure. We can use the “show databases” command outside the MySQL prompt with “echo” command to list databases on your server simply!! cool..

MySQL is one of the commonly using open source RDBMS (Relational DataBase Management System). We discussed a lot of topics related with MySQL server. MySQL is written in C and C++. Its SQL parser is written in yacc, but it uses a home-brewed lexical analyzer.

In this topic I’m going to list some tricks to list out the databases on your server without entering into the MySQL command prompt.

To list all databases on your server

You can use the following command to list all databases created on your MySQL server. Considering, the password is know and can access the databases without the user (root) password.

# echo "show databases;" | mysql

Sample output:

[email protected] [~]# echo "show databases;" | mysql

User without password

If your user does not have access to the MySQL server, you can select the right user with “-u” switch along with “mysql” command. Please see the sample command pasted below:

# echo "show databases;" | mysql -u $user [Replace $user with the right user with access to MySQL database]


# echo "show databases;" | mysql -u root

If you need a password, append “-p” switch along with the aforementioned command. Please see the example pasted below:

# echo "show databases;" | mysql -p -u $user [Replace $user with the right user with access to MySQL database]


# echo "show databases;" | mysql -p -u root

You should be prompted for your MySQL user password, and upon authenticating the user successfully, a list of databases will be printed to stdout and you will be returned to the BASH command prompt instantly.

That’s it dude!! If you have any questions please comment below or create a topic in our discussion board.

, ,

Post navigation

Arunlal Ashok

Operations Engineer at Endurance International Group. Linux lover. Like to play on Linux console. I started this blog to share and discuss Linux thoughts.

Always happy for an open discussion! Write to arun (@) crybit (dot) com. Check about me for more details. About this blog and our strong members, check The team
Please follow the LinkedIn page

One thought on “List all MySQL databases from Linux command line

  1. Hey, from the blog information I collect some good information and I hope if you interested in it then that will be fine to know about it.

Leave a Reply

Your email address will not be published. Required fields are marked *