在硬件非常优秀时 为了避免浪费硬件的性能
采用多实例
实践
创建目录
mkdir -p /data/330{7,8,9}/data
准备配置文件
cat > /data/3307/my.cnf<<EOF
[mysqld]
user=mysql
basedir=/application/mysql
datadir=/data/3307/data
socket=/tmp/3307/mysql.sock
server_id=7
prot=3307
log_error=/data/3307/data/mysql.log
log_bin=/data/3307/data/mysql-bin
EOF
cat > /data/3308/my.cnf<<EOF
[mysqld]
user=mysql
basedir=/application/mysql
datadir=/data/3308/data
socket=/tmp/3308/mysql.sock
server_id=8
prot=3308
log_error=/data/3308/data/mysql.log
log_bin=/data/3308/data/mysql-bin
EOF
cat > /data/3309/my.cnf<<EOF
[mysqld]
user=mysql
basedir=/application/mysql
datadir=/data/3309/data
socket=/tmp/3309/mysql.sock
server_id=9
prot=3309
log_error=/data/3309/data/mysql.log
log_bin=/data/3309/data/mysql-bin
EOF
初始化三套数据
mv /etc/my.cnf /etc/my.cnf.bak
mysqld --initialize-insecure --user=mysql --datadir=/data/3307/data --basedir=/application/mysql
mysqld --initialize-insecure --user=mysql --datadir=/data/3308/data --basedir=/application/mysql
mysqld --initialize-insecure --user=mysql --datadir=/data/3309/data --basedir=/application/mysql
systemd管理多实例
cd /etc/systemd/system
cp mysqld.service mysqld3307.service
cp mysqld.service mysqld3308.service
cp mysqld.service mysqld3309.service
vim mysqld3307.service
ExecStart=/application/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf
vim mysqld3308.service
ExecStart=/application/mysql/bin/mysqld --defaults-file=/data/3308/my.cnf
vim mysqld3309.service
ExecStart=/application/mysql/bin/mysqld --defaults-file=/data/3309/my.cnf
授权
chown -R mysql.mysql /data/*
启动
systemctl start mysqld3307.service
systemctl start mysqld3308.service
systemctl start mysqld3309.service
验证多实例有无创建成功
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"