shell脚本之连接mysql并监控数据库实战

#!/bin/bash
mysql=$(which mysql)


MYSQL_USER=root
MYSQL_PASSWORD=1234
MYSQL_Host=localhost
${mysql} -u${MYSQL_USER} -p${MYSQL_PASSWORD} -h${MYSQL_Host} -e "select version();"
Number_Connect=`${mysql} -u${MYSQL_USER} -p${MYSQL_PASSWORD} -h${MYSQL_Host} -e "show full processlist" 2>&1|grep -v Warning|wc -l`
echo $Number_Connect

脚本测试:

[mysql@t3-dtpoc-dtpoc-web06 liys]$ sh monitor.sh
mysql: [Warning] Using a password on the command line interface can be insecure.
+------------+
| version()  |
+------------+
| 5.7.26-log |
+------------+
2

你可能感兴趣的:(mysql,数据库)