MYSQL: How to check exit status?

∥☆過路亽.° 提交于 2019-12-11 15:09:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!