mysql数据库主主、主从配置和语句例子如下
mysql数据库主主、主从配置和语句例子如下:
主从模式
主1:mysql.cnf配置
server-id=202
log-bin=mysql-bin
binlog-format=mixed
主1sql语句
grant replication create,replication slave on *.* to repl@'192.168.1.110' identify by 'repl'
从2:mysql.cnf配置
server-id=203
log-bin=mysql-bin
binlog-format=mixed
relay-log=mysql-relay
从2SQL语句:
start slave
change master to
master_host='192.168.1.202',
master_user='repl',
master_password='repl',
master_log_file='mysql-bin.000001',
master_log_pos=111
主主模式:
主1:mysql.cnf配置
server-id=202
bin-log=mysql-bin
binlog-format=mixed
relay-log=mysql-relay
主1sql语句:
grant replication client,replication slave on *.* master202@'192.168.1.202' identified by 'master2020111'
cahnge master to
master_host='192.168.1.203',
master_user='master203',
master_password='master203111',
# 主2的master日志文件
master_log_file='mysql-bin.000001'
# 主2的master日志文件读取位置
master_log_pos=1;
start slave;
主2:mysql.cnf配置
server-id=203
bin-log=mysql-bin
binlog-farmat=mixed
relay-log=mysql-relay
主2sql语句:
grant replication client,replication slave on *.* master203@'192.168.1.203' identified by 'master203111';
change master to
master_host='192.168.1.202'
master_user=master202,
master_password='master202111',
# 主1的master日志文件
master_log_file='mysql-bin.000001',
# 主1的master日志文件读取位置
master_log_pos=1;
start slave;
重置:reset slave;
查看状态;
show master status
show slave status
主主两个服务器的master_log_file、master_log_pos要查找相互的master最新值,特别是pos值
posted on 2020-09-27 14:36 dong瓜(TreeSky) 阅读(104) 评论(0) 编辑 收藏 举报