1- 多实例准备数据存储路径
[root@db01 ~]# mkdir /data/mysql330{7,8,9}/data -p
2- 配置文件 详细
(1)cp配置文件到对应的文件夹
[root@db01 ~]# cp /etc/my.cnf /data/mysql3307/
[root@db01 ~]# cp /etc/my.cnf /data/mysql3308/
[root@db01 ~]# cp /etc/my.cnf /data/mysql3309/
(2)修改对应文件夹的配置文件如下:
[root@db01 ~]# cat /data/mysql3307/my.cnf
[mysqld]
user=mysql
basedir=/application/mysql
datadir=/data/mysql3307/data
socket=/data/mysql3307/mysql.sock
server_id=7
log_bin=/data/binlog3307/mysql-bin
binlog_format=row
port=3307
autocommit=0
log_error=/tmp/mysql3307_error.log
gtid-mode=on
enforce-gtid-consistency=true
slow_query_log=1
slow_query_log_file=/data/mysql3307/slow.log
long_query_time=0.1
log_queries_not_using_indexes
3- 初始化多实例数据库
mv /etc/my.cnf /etc/my.cnf.bak
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql3307/data --basedir=/application/mysql
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql3308/data --basedir=/application/mysql
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql3309/data --basedir=/application/mysql
4- systemctl启动数据库配置
[root@db01 ~]# cat /etc/systemd/system/mysqld3307.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
# 修改为:--defaults-file=/data/mysql3307/my.cnf
ExecStart=/application/mysql/bin/mysqld --defaults-file=/data/mysql3307/my.cnf
LimitNOFILE = 5000
EOF
(1)目录授权
[root@db01 ~]# chown -R mysql.mysql /data
(2) 启动数据库
systemctl start mysqld3307.service
systemctl start mysqld3308.service
systemctl start mysqld3309.service
5- 验证多实例
netstat -lnp|grep 330
mysql -S /data/3307/mysql.sock -e "select @@server_id"
mysql -S /data/3308/mysql.sock -e "select @@server_id"
mysql -S /data/3309/mysql.sock -e "select @@server_id"