问题
I've a problem with mysql remote connections. One server located in USA, the other located in Netherlands and the connection between them is horrible, especially in the evenings.
I managed to solve the select
query by setting a timeout
done < <(mysql --connect_timeout=10 --batch -e "${selectQ}" -u${user} -p${password} ${database} -h ${host})
but I don't know how to solve update
query, as it should be send only once.
echo "UPDATE table set field='1' WHERE id='${id}'" | mysql -u${user} -p${password} ${database} -h ${host}
回答1:
same way:
echo "UPDATE table set field='1' WHERE id='${id}'" |
mysql --connect_timeout=10 -u${user} -p${password} ${database} -h ${host}
in order to check the results, here's an example:
myhost:~ # echo "silly query;"|mysql -unoone -pwrong DBEMPTY -hlocalhost
ERROR 1045 (28000): Access denied for user 'noone'@'localhost' (using password: YES)
myhost:~ # echo $?
1
myhost:~ # echo "select 0;"|mysql -uvaliduser -pproperpassword MYTESTDB -hlocalhost
0
0
myhost:~ # echo $?
0
来源:https://stackoverflow.com/questions/21369396/mysql-how-to-check-exit-status