mysql基础管理-多实例配置

mysql的多实例 

1)规划

配置文件 3份 /data/330[7..9]/my.cnf    

数据目录 3份 /data/330[7..9]

日志目录 3份 /binlog/330[7..9]

socket 3份 /tmp/mysql330[7..9].sock

端口  3份 port= 3307,3308,3309 

server_id 3份 7,8,9 

2)配置过程

1.创建目录

mkdir -p  /data/330{7..9}/data

mkdir  -p /binlog/330{7..9}

2.创建配置文件 

cat  >  /data/3307/my.cnf <

[mysqld]

basedir=/usr/local/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 <

[mysqld]

basedir=/usr/local/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 <

[mysqld]

basedir=/usr/local/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 


3.初始化数据

赋权:chown -R mysql.mysql /data /binlog 

将原始配置文件重命名:mv /etc/my.cnf  /etc/my.cnf.bak

初始化:

mysqld --initialize-insecure --user=mysql --datadir=/data/3307/data --basedir=/usr/local/database/mysql

mysqld --initialize-insecure --user=mysql --datadir=/data/3308/data --basedir=/usr/local/database/mysql

mysqld --initialize-insecure --user=mysql --datadir=/data/3309/data --basedir=/usr/local/database/mysql

4.准备启动脚本

vim /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

ExecStart=/usr/local/database/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf

LimitNOFILE=5000


---启动多实例

systemctl start mysqld3307 

systemctl start mysqld3308

systemctl start mysqld3309  

登陆多实例:

mysql -S /tmp/mysql3307.sock


--关闭多实例

systemctl stop mysqld3307 

systemctl stop mysqld3308

systemctl stop mysqld3309

你可能感兴趣的:(mysql基础管理-多实例配置)