GIS数据共享:官方网站

MySQL

当前位置:首页 > 数据库 > MySQL

MySQL主从同步

MySQL主从同步

准备工作

        两个不同的MySQL。

        建议MySQL版本不要太大,否则会出现各种问题,如果你的主从版本差异较大,请自行百度设置同步后可能出现的问题。

设置权限

登陆服务器,进入MySQL,推荐使用root登陆MySQL;

mysql -u root -p

设置权限

grant all privileges on 数据库名.* to '用户名'@'%' identified by '密码';
flush privileges;

注意:两个数据库都要设置

启用主从同步

获取master_log_file和master_log_pos值

在主库执行如下语句:


flush logs;//用于刷新,可以不执行这句
show master status;

得到如下的内容:

image.png

其中File就是master_log_file,Postion就是master_log_pos。

本次截图,master_log_file=‘mysql-bin.000013’, master_log_pos=1276

执行同步

在备库执行如下语句:

STOP SLAVE;
reset slave;
change master to master_host='主库ip',master_port=端口号,master_user='用户名',master_password='密码',master_log_file='前面获取的
master_log_file',master_log_pos=前面获取的master_log_pos;
start slave;

查看同步状态

show slave status;
show slave status\G;


错误一解决

Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it).

出现上述问题的原因是主从的server ids一致,需要不一样。进入主数据库或者从数据库服务器,打开/etc/my.conf文件,修改server-id为其它的值;

扫码查看

相关内容

文章评论

表情

共 0 条评论,查看全部
  • 这篇文章还没有收到评论,赶紧来抢沙发吧~

评论排行榜

热门标签