Mysql下载

https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz

 

Mysql版本:5.7.26

Mysql安装方式:二进制

 

多实例的应用

1、准备多个目录

mkdir -p /mysql/330{7,8,9}/data

 

2、准备配置文件

cat > /mysql/3307/my.cnf <<EOF
[mysqld]
basedir=/application/mysql   #mysql安装路径
datadir=/mysql/3307/data     #mysql数据存放目录
socket=/mysql/3307/mysql.sock  #mysql的socket
log_error=/mysql/3307/mysql.log
port=3307
server_id=7
log_bin=/mysql/3307/mysql-bin
EOF

cat > /mysql/3308/my.cnf <<EOF
[mysqld]
basedir=/application/mysql
datadir=/mysql/3308/data
socket=/mysql/3308/mysql.sock
log_error=/mysql/3308/mysql.log
port=3308
server_id=8
log_bin=/mysql/3308/mysql-bin
EOF

cat > /mysql/3309/my.cnf <<EOF
[mysqld]
basedir=/application/mysql
datadir=/mysql/3309/data
socket=/mysql/3309/mysql.sock
log_error=/mysql/3309/mysql.log
port=3309
server_id=9
log_bin=/mysql/3309/mysql-bin
EOF

3、初始化三套数据

mysqld --initialize-insecure  --user=mysql --datadir=/mysql/3307/data --basedir=/application/mysql
mysqld --initialize-insecure  --user=mysql --datadir=/mysql/3308/data --basedir=/application/mysql
mysqld --initialize-insecure  --user=mysql --datadir=/mysql/3309/data --basedir=/application/mysql

4、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=/mysql/3307/my.cnf
vim mysqld3308.service
ExecStart=/app/mysql/bin/mysqld  --defaults-file=/mysql/3308/my.cnf
vim mysqld3309.service
ExecStart=/app/mysql/bin/mysqld  --defaults-file=/mysql/3309/my.cnf

 

 

5、授权

chown -R mysql.mysql /mysql/*

 

6、启动

systemctl start mysqld3307.service
systemctl start mysqld3308.service
systemctl start mysqld3309.service

7、验证多实例

netstat -lnp|grep 330
mysql -S /mysql/3307/mysql.sock -e "select @@server_id"
mysql -S /mysql/3308/mysql.sock -e "select @@server_id"
mysql -S /mysql/3309/mysql.sock -e "select @@server_id"

Mysql多实例启动_linux