分享一个自己写mysql起停脚本,方便测试环境多实例其他操作
[root@node2 ~]# cat /sbin/mysqlsrv
#!/bin/bash
mysql_dir=/usr/local/mysql/
mysql_dat=/data
if [ "$2" = "" ]
then
port=3306
else
port="$2"
fi
function mysql_process_cnt()
(ps -ef|grep -v "grep"|grep mysql$port|wc -l)
function mysql_start()
(/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my$port.cnf &)
function mysql_kill()
(
#ps -ef|grep mysql|grep $port|awk -F' ' '{print $2}'|xargs kill -9
mysqladmin -uroot -pshunzi -S /data/mysql$port/tmp/mysql$port.sock shutdown
)
function mysql_stat()
(mysqladmin -uroot -pshunzi -S /data/mysql$port/tmp/mysql$port.sock -r -i 1 ext |\
awk -F"|" \
"BEGIN{ count=0; }"\
'{ if($2 ~ /Variable_name/ && ((++count)%20 == 1)){\
print "----------|---------|--- MySQL Command Status --|----- Innodb row operation ----|-- Buffer Pool Read --";\
print "---Time---|---QPS---|select insert update delete| read inserted updated deleted| logical physical";\
}\
else if ($2 ~ /Queries/){queries=$3;}\
else if ($2 ~ /Com_select /){com_select=$3;}\
else if ($2 ~ /Com_insert /){com_insert=$3;}\
else if ($2 ~ /Com_update /){com_update=$3;}\
else if ($2 ~ /Com_delete /){com_delete=$3;}\
else if ($2 ~ /Innodb_rows_read/){innodb_rows_read=$3;}\
else if ($2 ~ /Innodb_rows_deleted/){innodb_rows_deleted=$3;}\
else if ($2 ~ /Innodb_rows_inserted/){innodb_rows_inserted=$3;}\
else if ($2 ~ /Innodb_rows_updated/){innodb_rows_updated=$3;}\
else if ($2 ~ /Innodb_buffer_pool_read_requests/){innodb_lor=$3;}\
else if ($2 ~ /Innodb_buffer_pool_reads/){innodb_phr=$3;}\
else if ($2 ~ /Uptime / && count >= 2){\
printf(" %s |%9d",strftime("%H:%M:%S"),queries);\
printf("|%6d %6d %6d %6d",com_select,com_insert,com_update,com_delete);\
printf("|%6d %8d %7d %7d",innodb_rows_read,innodb_rows_inserted,innodb_rows_updated,innodb_rows_deleted);\
printf("|%10d %11d\n",innodb_lor,innodb_phr);\
}}')
case $1 in
start)
if [ mysql_process_cnt
-gt 0 ]
then
echo 'Mysql Server is running!'
else
mysql_start
echo 'Begin startup mysql...'
sleep 5;
if [ mysql_process_cnt
-gt 0 ]
then
echo 'Mysql Server is startup!'
else
echo 'Mysql Server is startup error!'
fi
fi
;;
stop)
if [ mysql_process_cnt
-gt 0 ]
then
mysql_kill
echo 'Begin stop mysql...'
sleep 5;
if [ mysql_process_cnt
-gt 0 ]
then
echo 'Mysql Server is stop error!'
else
echo 'Mysql Server is stop ok!'
fi
else
echo 'Mysql Server is not run!'
fi
;;
cnt)
echo mysql_process_cnt
"$2" mysql$port
;;
mysql)
mysql -uroot -pshunzi -S /data/mysql$port/tmp/mysql$port.sock
;;
stat)
mysql_stat
;;
*)
echo "### Usage: ### default port 3306"
echo "==================================================="
echo "mysqlsrv start port #start the port's mysql server!"
echo "mysqlsrv stop port #stop the port's mysql server!"
echo "mysqlsrv cnt port #view the port's process info!"
echo "mysqlsrv stat port #view the port's server status!"
echo "==================================================="
;;
esac
继续阅读
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏