centos7配置mysql多实例启动

背景:
在已经安装mysql并启动单实例的情况下,新增实例。
mysql5.7

可参考https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html Configuring Multiple MySQL Instances Using systemd

一、先备份/etc/my.cnf
cp /etc/my.cnf /etc/my.cnf.bak

二、停止单实例
systemctl stop mysqld

三、编辑/etc/my.cnf
[mysqld@replica01]
datadir=/var/lib/mysql-replica01
socket=/var/lib/mysql-replica01/mysql.sock
port=3307
log-error=/var/log/mysqld-replica01.log

[mysqld@replica02]
datadir=/var/lib/mysql-replica02
socket=/var/lib/mysql-replica02/mysql.sock
port=3308
log-error=/var/log/mysqld-replica02.log

四、初始化数据库
mysqld --initialize --basedir=/usr/lib64/mysql/ --datadir=/var/lib/mysql-replica02

五、启动数据库
systemctl start mysqld@replica01
systemctl start mysqld@replica02

六、访问数据库
mysql -uroot -p -S /var/lib/mysql-replica02/mysql.sock

你可能感兴趣的:(centos7配置mysql多实例启动)