开发者

Shell and MySQL custom connection success message

How can I print 开发者_开发知识库a custom success message if connected to mysql via shell? Instead of displaying mysql error messages. Something like this

if [ "$mysql_connected" ]; then
  echo "connected"
  # do mysql stuff
else
  echo "connection failed"
fi

Thanks in advance!


Use exit status as shown below:

mysql -uroot -pabc -e"show databases;"
if [ $? -eq 0 ];then
echo "success";
else
echo "failed to connect";
fi
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜