#mysql安装
#解压
tar -zxvf mysql-5.7.31-el7-x86_64.tar.gz
#修改包名
mv mysql-5.7.31-el7-x86_64 mysql5.7
#进入到目录中
cd ./mysql5.7/
#创建数据目录
mkdir data
#添加用户组
groupadd mysql
#创建用户组全局权限
useradd -M -g mysql -s /sbin/nologin -d /opt/mysql5.7 mysql
#给用户组赋值目录权限
chown -R mysql.mysql /opt/mysql5.7/
#初始化数据库
./bin/mysqld --initialize --user=mysql --basedir=/opt/mysql5.7 --datadir=/opt/mysql5.7/data --console
#修改/etc/my.cnf
[mysqld]
datadir=/opt/mysql5.7/data
socket=/opt/mysql5.7/data/mysql.sock
#设置密码
set password for root@localhost = password('wsj33233');
主从
#修改主服务器
#开启二进制日志
log-bin=mysql-bin
#配置服务器id
server-id=1
#修改从服务
#开启二进制日志 非必须
log-bin=mysql-bin
#配置服务器id
server-id=2
#配置主服务器172.16.xx.xxx 开启权限连接
GRANT REPLICATION SLAVE ON *.* to 'root'@'%' identified by 'passwd';
#开通主服务器外部访问权限
grant all privileges on *.* to root@'%' identified by "passwd";
#登陆主库查看主库状态 注:执行完此步骤后不要再操作主服务器MYSQL,防止主服务器状态值变化
show master status;
#配置从库连接中继日志拉取主库信息
change master to master_host='172.16.xx.xxx',master_user='root',master_password='passwd',master_log_file='mysql-bin.000003',master_log_pos=36544,master_port=3307;
#启动从库备份
start slave;
#查看从库的复制状态
show slave status\G;
#问题排错
ERROR 3021 (HY000): This operation cannot be performed with a running slave io thread; run STOP SLAVE IO_THREAD FOR CHANNEL '' first.
STOP slave;
#36544 偏移量
master_host='172.16.14.108',master_user='root',master_password='passwd',master_log_file='mysql-bin.000003',master_log_pos=36544,master_port=3307;
start slave;
#Slave_SQL_Running: No
STOP slave;
SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
start slave;