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
Database
information_schema
lavasya_nel
lavasya_tech24
lavasya_wrdp1
anvew_wordpress
apoel_apollotransformers_db
apoel_bass_db

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]

Example

# 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]

Example

# 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 A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

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 *