时间:2021-07-01 10:21:17 帮助过:28人阅读
#netstat -tnlp | grep ":$port " > $txtfile
#value=`cat $txtfile|awk ‘{print $4}‘|awk -F ":" ‘{print $2}‘`
sleep 10
value=`netstat -tnlp | grep ":$port " | awk ‘{print $4}‘ | awk -F‘:‘ ‘{print $NF}‘`
#echo $value
if [ "${value}" -eq "${port}" ];then
printf "MYSQL is up...!\n"
else
printf "MYSQL is not startup...!\n"
fi
else
printf "MYSQL is runing...\n"
exit
fi
}
#stop function
function_stop_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "MYSQL is stopped...\n"
exit
else
printf "Stoping MYSQL...\n"
${CmdPath}/mysqladmin -u${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown && echo "MYSQL is down...!"
fi
}
#restart function
function_restart_mysql()
{
printf "Restarting NYSQL...\n"
function_stop_mysql
sleep 2
function_start_mysql
}
case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage:/data/${port}/mysql {start|stop|restart}\n"
esac
# cp /data/3306/mysqld /data/3307/mysqld
# sed ‘s/3306/3307/g‘ /data/3307/mysqld
至此两个实例的数据文件,配置文件,启动文件都已完成配置。
五:配置MYSQL多实例的文件权限
1:授权mysql用户管理整个多实例的根目录/data
#chown -R mysql.mysql /data
2:因为启动文件中有数据库的密码信息,因此应设置700权限最佳
#find /data -name mysqld | xargs chmod 700
六:将Mysql命令加入全局路径,方便使用。
# echo ‘export PATH=/application/mysql/bin:$PATH‘ >>/etc/profile
# source /etc/profile (直接生效)
# echo $PATH (查看配置是否成功)
七:初始化MYSQL多实例的数据库文件(初始化数据库的实质就是创建基础的数据库的库文件)
# cd /application/mysql/scripts
# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql
# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3307/data --user=mysql
八:启动MYSQL多实例数据库
# /data/3306/mysqld start(stop|restart)
九:配置MYSQL数据库开机自启动
# echo "#mysql multi Instances" >> /etc/rc.local
# echo "/data/3306/mysql start" >> /etc/rc.local
# echo "/data/3307/mysql start" >> /etc/rc.local
十:登陆测试以及安全配置(为mysql设置密码登陆)
# mysql -S /data/3306/mysql.sock
# mysqladmin -uroot -S /data/3306/mysql.sock password ‘niutianwen‘
至此单机MYSQL双实例的配置已经完成!如要再增加MYSQL实例上去只要重复上述过程即可!谢谢大家。专注linux之路让大家不在孤单!
本文出自 “专注Linux技术交流” 博客,请务必保留此出处http://niutianwen.blog.51cto.com/10716187/1865228
MYSQL的单机多实例部署
标签:mysql的单机多实例部署详解