mysql8.0主从同步_mysql8.0 主从同步

环境:关闭防火墙、selinux

192.168.17.132  master1

192.168.17.134  master2

1、编辑配置文件

master1配置文件

vi /etc/my.cnf

[client]

port=3306socket=/tmp/mysql/mysql.sock

[mysqld]

port=3306user=mysql

socket=/tmp/mysql/mysql.sock

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

log-error=error.log

log_bin=mysql-bin

server_id= 1sync_binlog=1slave-skip-errors=all

auto_increment_increment=2auto_increment_offset=1transaction_isolation= READ-COMMITTED

character-set-server =utf8mb4

collation-server =utf8mb4_general_ci

default_authentication_plugin=mysql_native_password

lower_case_table_names= 1#skip-grant-tables

master2配置文件

vi /etc/my.cnf

[client]

port=3306socket=/tmp/mysql/mysql.sock

[mysqld]

port=3306user=mysql

socket=/tmp/mysql/mysql.sock

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

log-error=error.log

log-bin=mysql-bin          #####

server-id = 2            #####slave-skip-errors=all       #####

sync_binlog=1            #####auto_increment_increment=2    #####auto_increment_offset=2      #####transaction_isolation= READ-COMMITTED

character-set-server =utf8mb4

collation-server =utf8mb4_general_ci

lower_case_table_names= 1default_authentication_plugin=mysql_native_password

2、重启服务

/usr/local/mysql/support-files/mysql.server start/stop/restart

3、创建授权用户

create user mysqlrepl@'192.168.17.%';

update user set authentication_string='' where user='mysqlrepl';

alter user 'mysqlrepl'@'192.168.17.%' identified with mysql_native_password by '123456';

grant all privileges on . to mysqlrepl@'192.168.17.%%' identified by '123456' with grant option ;

查看授权用户

select host, user, authentication_string, plugin from mysql.user;

show grants for mysqlrepl@'192.168.17.%';

4、查看mster信息

show mater status\G;

mater1信息:

49321bd1e9e75261999c83c29cbd0439.png

master2信息:

71e42546b00a6d778e22b4561c30fe05.png

5、在slave创建master信息

master1执行:change master to master_host='192.168.17.134',master_user='mysqlrepl', master_password='123456',master_log_file='mysql-bin.000002',master_log_pos=932;

master2执行:change master to master_host='192.168.17.132',master_user='mysqlrepl', master_password='123456',master_log_file='mysql-bin.000007',master_log_pos=156;

6、开启master1和master2的slave:

start slave

查看状态:show slave status\G;

bd8534aa3a110396c7bc5b5fe71209e4.png

20d807d78b03070c1a894a722753860d.png

7、验证:在master1上创建库1、在master2上创建库2

2a3400776caab6db74f19cbe9692b544.png

同步成功。

注:Mysql在V5.1之前默认存储引擎是MyISAM;在此之后默认存储引擎是InnoDB

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值