Reputation: 1
I'm trying to run mysql command into a docker container from a remote machine, through SSH. In particular the command is this one:
ssh user@servername /usr/bin/sudo /usr/bin/docker exec CONTAINER '/usr/bin/mysql --user=USER --password=PASSWORD -e "show databases;"'
I receive this response: ERROR 1049 (42000): Unknown database 'databases;"'
The same command (/usr/bin/sudo /usr/bin/docker exec CONTAINER /usr/bin/mysql --user=USER --password=PASSWORD -e "show databases;") launched on the machine where the container is running, works!
Someone could help me? thank you
Upvotes: 0
Views: 663
Reputation: 1
I resolved using /usr/bin/mysqlshow instad of /usr/bin/mysql. Now it returns the database list correctly. I post the entire command i use to save the mysql docker container database list remotely:
LIST_DB=($(ssh -q USER@SERVERNAME /usr/bin/sudo /usr/bin/docker exec CONTAINER "/usr/bin/mysqlshow -u USER -pPASSWORD" 2>&1 | sed 's/|//g' | sed 's/\-//g' | sed 's/\+//g' |sed -e 's/^[[:blank:]]*//g' | grep -v "Using a password" | grep -Ev "_schema|tmp|innodb|sys|Databases"))
Upvotes: 0
Reputation: 1627
use this command
ssh user@servername 'sudo docker exec CONTAINER mysql --user=USER --password=PASSWORD -e "show databases;"'
We have to pass the complete command (to be executed on remote shell) in quotes('').
Upvotes: 1