一台centos7.5主机实现多实例mysql
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一台centos7.5主机实现多实例mysql相关的知识,希望对你有一定的参考价值。
实验:一台centos7.5主机实现多实例mysql
规划:
3306 3307 3308 端口,共3个实例
目录:
/data/mysql{3306,3307,3308}
/data/mysql/330{6,7,8}/{etc,log,data,pid,bin,socket}
具体实现:
[[email protected] ~]# yum install mariadb-server
[[email protected] ~]# rpm -ql mariadb-server
/usr/libexec/mysqld //二进制程序
/usr/bin/mysql_install_db //生成初始化数据库脚本
[[email protected] data]# cd /data/
[[email protected] data]# mkdir mysql/{3306,3307,3308}/{etc,data,socket,log,bin,pid} -pv、
[[email protected] ~]# ls /var/lib/mysql/ //默认数据库文件路径
[[email protected] data]# chown -R mysql.mysql mysql/
[[email protected] data]# /usr/bin/mysql_install_db --datadir=/data/mysql/3306/data --user=mysql //在(330{6,7,8})实例目录下生成初始化数据库文件。
[[email protected] ~]# cp /etc/my.cnf /data/mysql/3306/etc/
[[email protected] ~]# vi /data/mysql/3306/etc/my.cnf //把该配置文件分别复制到3307,3308实例目录并修改成3307和3308
[mysqld]
port=3306
datadir=/data/mysql/3306/data
socket=/data/mysql/3306/socket/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/data/mysql/3306/log/mariadb.log
pid-file=/data/mysql/3306/pid/mariadb.pid
[[email protected] /data/mysql/3306/bin]# rz mysqld //上传服务脚本到330{6,7,8}/bin/目录下并修改端口
主要修改下面两项即可:
port=3306
mysql_basedir="/data/mysql"
[[email protected] 3306]# bin/mysqld start //启动成功
[[email protected] 3307]# bin/mysqld start //启动成功
[[email protected] 3308]# bin/mysqld start //启动成功
[[email protected] ~]# mysql -S /data/mysql/3308/socket/mysql.sock //客户端连接到某一个服务端。
myslqd脚本:
#!/bin/bash
#chkconfig: 345 20 80
# chkconfig --add mysqld3306 ......
port=3306
mysql_user="root"
mysql_pwd=""
cmd_path="/usr/bin"
mysql_basedir="/mysqldb"
mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"
function_start_mysql(){
if [ ! -e "$mysql_sock" ];then
printf "Starting MySQL...
"
${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null &
else
printf "MySQL is running...
"
exit
fi
}
function_stop_mysql(){
if [ ! -e "$mysql_sock" ];then
printf "MySQL is stopped...
"
exit
else
printf "Stoping MySQL...
"
${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown
fi
}
function_restart_mysql(){
printf "Restarting MySQL...
"
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: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}
"
esac
以上是关于一台centos7.5主机实现多实例mysql的主要内容,如果未能解决你的问题,请参考以下文章