Pawel Miszkurka Pawel Miszkurka - 5 months ago 8
SQL Question

Querying remote MySql database with bash

I'm trying to query remote database with the following script.

some_db="somedb"
isAnythingToProcess=$(mysql -uroot -proot -D$some_db -e "$checkSearch");


This works for me locally however whenever i try to run bash script to remote AWS server I get error


ERROR 1049 (42000): Unknown database 'somedb'


Any hints?

P.S. The database exists for sure. I can connect to it via MySQL client.

Answer

You need to add the parameter for remote host -h

some_db="somedb"
isAnythingToProcess=$(mysql -uroot -proot -h REMOTE_IP -D$some_db -e "$checkSearch");