Run MySQL query on remote machine through ssh in command line

lk121 picture lk121 · Jul 9, 2013 · Viewed 62.7k times · Source

I am trying to run MySQL query on remote machine with this command:

ssh [email protected] "mysql -uroot -proot -e \"use test";""

I am not able to use that database.

Please suggest a working command.

Answer

kun tang picture kun tang · Jul 9, 2013

Try this:

mysql -h host -u root -proot -e "show databases;";