码迷,mamicode.com
首页 > 数据库 > 详细

mysql 互为主从

时间:2017-11-17 13:33:15      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:mysql 互为主从

ubuntu 服务器mysql5.9

开启功能分别在主从服务器上编辑mysql配置文件

#vim /etc/mysql/mysql.conf.d/mysqld.cnf  增加下面两行

bind-address = 0.0.0.0  #修改为允许任意服务器访问

log-bin=mysql

server-id=1    #主从数字不一样

重启服务

#/etc/init.d/mysql restart

进入mysql

建用户给权限

mysql>grant all privileges on *.* to user@’%’identified by ‘123‘;

mysql>show master status;

技术分享

1、先在主的上锁,注意上锁后在看一下master状态,保证File和Position不变。

mysql>FLUSH TABLES WITH READ LOCK;

mysql>unlock tables; #解锁在同步完成之后

2、在从上添加master

mysql>change master to master_host=‘192.168.1.141‘,master_user=‘user‘,

master_password=‘123‘,

master_port=3306,

master_log_file=‘mysql.000002‘,

master_log_pos=154;

查看slave的状态

mysql>stopslave;

技术分享

Slave_IO_Runing:Yes
Slave_SQL_Ringing:Yes

正常

如果出现No,看数据库日志报错

Slave SQL for channel ‘‘: Error executing row event: ‘Table ‘yunceshi.ph_smart_contract‘ doesn‘t exist‘, Error_code: 1146

配置文件中增加   slave-skip-errors = 1146

还可以把住的数据库备份,在导入到从的数据库中。

mysql 互为主从

标签:mysql 互为主从

原文地址:http://12927979.blog.51cto.com/12917979/1982754

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!