【Linux】shell判断mysql端口是否启用?

#!/bin/bash
set -eux

mysqld 2>&1 &
CONNECTED=$(netstat -alnt | grep -c ":3306 ")
while [ ${CONNECTED} -eq 0 ]; do
    echo "MYSQL NOT CONNECTED YET";
    sleep 1;
    CONNECTED=$(netstat -alnt | grep -c ":3306 ")
done
mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" -e "SHOW DATABASES;"
tail -f /var/log/mysql/error.log

参考资料:

http://www.unix.com/shell-programming-and-scripting/202841-simple-while-loop-script-check-connection.html

http://unix.stackexchange.com/questions/5277/how-do-i-tell-a-script-to-wait-for-a-process-to-start-accepting-requests-on-a-po

http://askubuntu.com/questions/82374/how-do-i-start-stop-mysql-server

http://www.dutycode.com/post-46.html

 

posted @ 2016-05-26 18:45  junneyang  阅读(656)  评论(0编辑  收藏  举报