I have a computer connected by SSH to another computer from which I want to run a bash script to query an external host in MySQL.
I connect without problems from the command line as follows:
mysql -h HOST -u USER -pPASS
Once connected, I use the database and others without problems.
The problem comes from using that same line in my script, I'm stuck with the script at that point for a while and then it sends me an error message like the following:
ERROR 2003 (HY000): Can't connect to MySQL server on 'HOST' (110)
This is my code:
if [ "$1" == "" ]
then
echo "Usage method: script-file + nodes-file"
exit 0
fi
NODES=$1
HOST="host"
USER="usuario"
PASS="Contraseña"
DB="BASE"
DATENOW='date +%d/%m/%Y-%H:%M --date "+2 hours"'
mysql -h $HOST -u $USER -p$PASS -D $DB -e "SHOW TABLES;"