mysql数据库主从配置详解
发布:smiling 来源: PHP粉丝网 添加日期:2014-10-14 13:45:56 浏览: 评论:0
将A设置为主,停止同步,代码如下:
slave stop;
清空服务器master日志:reset master;
授权同步账号:GRANT REPLICATION SLAVE ON *.* TO 'test'@'%' IDENTIFIED BY 'test';
刷新授权:flush privileges;
锁定数据库:flush tables with read lock;
将C设置为从,停止同步:slave stop;
配置同步信息,代码如下:
- CHANGE MASTER TO MASTER_HOST='10.1.10.28', MASTER_USER='test', MASTER_PASSWORD='test', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=107;
将C设置为主,停止同步:slave stop;
清空服务器master日志:reset master;
授权同步账号:GRANT REPLICATION SLAVE ON *.* TO 'test'@'%' IDENTIFIED BY 'test';
刷新授权:flush privileges;
锁定数据库:flush tables with read lock;
将A设置为从,停止同步:slave stop;
配置同步信息,代码如下:
- CHANGE MASTER TO MASTER_HOST='10.1.10.30', MASTER_USER='test', MASTER_PASSWORD='test', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=107;
2)将B设置为A的从,代码如下:
- server-id = 2
- replicate-do-db=test
- replicate-do-db=test_admin
- log-bin=mysql-bin
- log-slave-updates
- replicate-wild-do-table=test.%
- replicate-wild-do-table=test_admin.%
- binlog-ignore-db=mysql
- slave-skip-errors=all
重启mysql服务,停止同步:slave stop;
配置同步信息,代码如下:
- CHANGE MASTER TO MASTER_HOST='10.1.10.28', MASTER_USER='test', MASTER_PASSWORD='test', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=107;
启动同步:slave start;
3)将D设置为C的从,代码如下:
- server-id = 4
- replicate-do-db=test
- replicate-do-db=test_admin
- log-bin=mysql-bin
- log-slave-updates
- replicate-wild-do-table=test.%
- replicate-wild-do-table=test_admin.%
- binlog-ignore-db=mysql
- slave-skip-errors=all
- --phpfensi.com
重启mysql服务,停止同步:slave stop;
配置同步信息,代码如下:
- CHANGE MASTER TO MASTER_HOST='10.1.10.30', MASTER_USER='test', MASTER_PASSWORD='test', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=107;
启动同步:slave start;
完成之后可以创建添加数据测试一下是否可以.
下面是常见错误处理:
1)change master导致的,代码如下:
Last_IO_Error: error connecting to master 'repl1@IP:3306' - retry-time: 60 retries
2)在没有解锁的情况下停止slave进程,代码如下:
- mysql> stop slave;
- RROR 1192 (HY000): Can't execute the given command because you have active locked tables or an active transaction
3)change master语法错误,落下逗号,代码如下:
- mysql> change master to
- -> master_host='IP'
- -> master_user='USER',
- -> master_password='PASSWD',
- -> master_log_file='mysql-bin.000002',
- -> master_log_pos=106;
- ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'master_user='USER', --phpfensi.com
- master_password='PASSWD',
- master_log_file='mysql-bin.000002' at line 3
4)在没有停止slave进程的情况下change master,代码如下:
- mysql> change master to master_host=‘IP', master_user='USER', master_password='PASSWD', master_log_file='mysql-bin.000001',master_log_pos=106;
- ERROR 1198 (HY000): This operation cannot be performed with a running slave; run STOP SLAVE first
5)A B的server-id相同,代码如下:
- Last_IO_Error: 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-id,代码如下:mysql> show variables like 'server_id';
手动修改server-id,代码如下:
- mysql> set global server_id=2; #此处的数值和my.cnf里设置的一样就行
- mysql> slave start;
6) change master之后,查看slave的状态,发现slave_IO_running 为NO.
好了,这篇文章总共计到了mysql主从配置与数据相互主从配置配置教程.
Tags: mysql主从 数据库主从
- 上一篇:sql分组取最大记录方法
- 下一篇:mysql 百万条数据分页优化
相关文章
- ·MySQL主从设置方法介绍(2014-09-23)
- ·mysql主从复制与数据同步Slave_IO_Running错误(2014-09-24)
- ·mysql数据库搭建主从服务器配置详解(2014-09-24)
- ·完整的mysql主从配置方法详解(2014-09-24)
- ·简单的MySQL数据库主从同步配置(2014-09-24)
- ·mysql数据库主从同步的问题解决方法(2014-09-24)
- ·mysql数据库主从复制部署笔记(2014-09-24)
- ·mysql服务器主从数据库同步配置(2014-09-24)
- ·CENTOS6.3中MYSQL主从数据库备份配置(2014-09-28)
- ·mysql 5.5数据库主从配置步骤详解(2014-10-01)
- ·添加新数据库到MySQL主从复制列表(2014-10-02)
- ·mysql主从复制安装配置,从线上环境配置主从(2014-10-02)
- ·MySQL主从复制下改变主服务器IP配置过程(2014-10-02)
- ·MySQL主从复制配置 MySQL数据自动备份配置(2014-10-03)
- ·安全删除mysql主从复制二进制日志详解(2014-10-04)
- ·Windows系统mysql服务器主从数据同步备份(2014-10-05)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)