-
-
节约服务器资源;
-
-
-
数据库目录不能相同
-
启动脚本不能同名
-
端口不能相同
-
创建用户和组
#用户不登录系统 useradd mysql -s /sbin/nologin id mysql uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)
pkill mysqld
rm -rf /data/330{7..9}/data/* rm -rf /binlog/330{7..9}/data/* mkdir -p /app/database/ cd /app/database/ tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz ln -s mysql-5.7.28-linux-glibc2.12-x86_64 mysql mkdir -p /data/330{7..9}/data mkdir -p /binlog/330{7..9}
cat > /data/3307/my.cnf <<EOF [mysqld] basedir=/app/database/mysql datadir=/data/3307/data socket=/tmp/mysql3307.sock log_error=/data/3307/mysql.log port=3307 server_id=7 log_bin=/binlog/3307/mysql-bin EOF cat > /data/3308/my.cnf <<EOF [mysqld] basedir=/app/database/mysql datadir=/data/3308/data socket=/tmp/mysql3308.sock log_error=/data/3308/mysql.log port=3308 server_id=8 log_bin=/binlog/3308/mysql-bin EOF cat > /data/3309/my.cnf <<EOF [mysqld] basedir=/app/database/mysql datadir=/data/3309/data socket=/tmp/mysql3309.sock log_error=/data/3309/mysql.log port=3309 server_id=9 log_bin=/binlog/3309/mysql-bin EOF
yum install libaio -y
chown -R mysql.mysql /data /binlog mv /etc/my.cnf /etc/my.cnf.bak mysqld --initialize-insecure --user=mysql --datadir=/data/3307/data --basedir=/app/database/mysql mysqld --initialize-insecure --user=mysql --datadir=/data/3308/data --basedir=/app/database/mysql mysqld --initialize-insecure --user=mysql --datadir=/data/3309/data --basedir=/app/database/mysql
#3307启动脚本 cat >/etc/systemd/system/mysqld3307.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/database/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf LimitNOFILE = 5000 EOF #3308启动脚本 cat >/etc/systemd/system/mysqld3308.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/database/mysql/bin/mysqld --defaults-file=/data/3308/my.cnf LimitNOFILE = 5000 EOF #3309启动脚本 cat >/etc/systemd/system/mysqld3309.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/database/mysql/bin/mysqld --defaults-file=/data/3309/my.cnf LimitNOFILE = 5000 EOF
systemctl daemon-reload
systemctl start mysqld3307
systemctl start mysqld3308
systemctl start mysqld3309
netstat -tulnp
登录数据库
mysql -S /tmp/mysql3307.sock mysql -S /tmp/mysql3308.sock mysql -S /tmp/mysql3309.sock