mysql数据库ip:192.168.32.201 系统版本 [root@vm01 ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) 数据库版本 mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
1、mysql5.7的二进制部署
省略
2、准备多个目录
mkdir -p /data/330{7,8,9}/data
3、准备配置文件
cat >> /data/3307/my.cnf <<EOF [mysqld] basedir=/app/mysql datadir=/data/3307/data socket=/data/3307/mysql.sock log_error=/data/3307/mysql.log port=3307 server_id=3307 log_bin=/data/3307/mysql-bin [mysql] socket=/data/3307/mysql.sock EOF cat >> /data/3308/my.cnf <<EOF [mysqld] basedir=/app/mysql datadir=/data/3308/data socket=/data/3308/mysql.sock log_error=/data/3308/mysql.log port=3308 server_id=3308 log_bin=/data/3308/mysql-bin [mysql] socket=/data/3308/mysql.sock EOF cat >> /data/3309/my.cnf <<EOF [mysqld] basedir=/app/mysql datadir=/data/3309/data socket=/data/3309/mysql.sock log_error=/data/3309/mysql.log port=3309 server_id=3309 log_bin=/data/3309/mysql-bin [mysql] socket=/data/3309/mysql.sock EOF
4、 初始化三套数据
mv /etc/my.cnf /etc/my.cnf.bak mysqld --initialize-insecure --user=mysql --datadir=/data/3307/data --basedir=/app/mysql mysqld --initialize-insecure --user=mysql --datadir=/data/3308/data --basedir=/app/mysql mysqld --initialize-insecure --user=mysql --datadir=/data/3309/data --basedir=/app/mysql
5、systemd管理多实例
cd /etc/systemd/system cp mysqld.service mysqld3307.service cp mysqld.service mysqld3308.service cp mysqld.service mysqld3309.service vim mysqld3307.service ExecStart=/app/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf vim mysqld3308.service ExecStart=/app/mysql/bin/mysqld --defaults-file=/data/3308/my.cnf vim mysqld3309.service ExecStart=/app/mysql/bin/mysqld --defaults-file=/data/3309/my.cnf
chown -R mysql.mysql /data/* chown -R mysql.mysql /app/mysql/*
systemctl start mysqld3307.service
systemctl start mysqld3308.service
systemctl start mysqld3309.service
8、测试
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"
cat >> /etc/systemd/system/mysqld.service <<EOF [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 ExecStart=/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf #注意mysqld的命令和配置文件路径 LimitNOFILE = 5000 EOF