zhuyumu 发表于 2018-10-3 09:09:54

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@'locahost'>  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
  还可以把住的数据库备份,在导入到从的数据库中。

页: [1]
查看完整版本: mysql 互为主从