启动mysql多实例
4.1. 脚本启动方式:
/usr/local/mysql/var/3306/mysqld start
将下面命令的方式写成脚本,利用case做{start|stop}
命令启动方式:
mysqld_safe --defaults-file=/usr/local/mysql/3306/my.cnf
4.2 创建mysql启动脚本
创建自动启动文件
vim /usr/local/mysql/var/3306/mysqld
3306的启动文件如下:
#!/bin/bash
mysql_port=3306
mysql_username="admin"
mysql_password="password"
start_mysql()
{
echo "Starting MySQL...\n"
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/dbdata_${mysql_port}/my.cnf 2>&1 > /dev/null &
}
stop_mysql()
{
echo "Stoping MySQL...\n"
/usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /data/dbdata_${mysql_port}/mysql.sock shutdown
}
restart_mysql()
{
echo "Restarting MySQL...\n"
stop_mysql
start_mysql
}
kill_mysql()
{
kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{echo $2}')
kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{echo $2}')
}
case $1 in
start)
start_mysql
;;
stop)
stop_mysql
;;
kill)
kill_mysql
;;
restart)
function_stop_mysql
function_start_mysql
;;
*)
echo "Usage: /data/dbdata_${mysql_port}/mysqld {start|stop|restart|kill}"
;;
esac
给文件755执行权chmod 755 /usr/local/mysql/var/3306/mysqld