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
精彩评论