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