I don't have remote access to a MySQL server, so I am trying to do it via an SSH session.
It partly works, but not correctly.
sshpass -p $password ssh user@$IP /bin/bash << EOF
mysql -N -uroot -ppassword test -e "select id from client where user ='$user'"
EOF
This will show the result of the select statement, but I'd like to be able to use that result in another echo statement.
eg:
The user ID is: xxxxx
I tried to assign the output to a variable using:
sshpass -p $password ssh user@$IP /bin/bash << EOF
res=$(mysql -N -uroot -ppassword test -e "select id from client where user ='$user'")
echo $res
EOF
But that results in:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysql/mysql.sock' (2)
If I quote EOF like 'EOF'
then I can get the result into res
but I lose the ability to use $user
Is there anyway to do this so I can use my variable in the heredoc and get the result of the MySQL query to a new variable ?