MYSQL 主从配置
来源:互联网 发布:java编写贪吃蛇教程 编辑:程序博客网 时间:2024/06/16 15:17
遇到的报错 (都是数据库版本不同导致的问题)
主数据库5.7 从5.1的
1、mysql同步复制抛Got fatal error 1236 Slave can not handle replication events with the checksum
这应该也是版本的问题
解决办法1:
master2的数据库换成5.6.12;
解决办法2:
在master1中设置binlog_checksum =none;
参数资料:http://blog.csdn.net/wantingtingting/article/details/41944047
2、当往MASTER数据库插数据的时候
SLVAE报错!!
Last_SQL_Errno: 1594
Last_SQL_Error: Relay log read failure: Could not parse relay log event entry.
虽然网上很多说stop slave;change master to master_log_file='mysql-bin.000001' ,master_log_pos=150;start slave; 有效
但是重新添加数据的时候又报错,应该是binarylog版本的问题了
没去看binarylog的版本 先把从数据升级
-----------------------------------------------------------------------------开始配置------------------------------------------------------------------------------------
1、准备两台主机
主 - 本地IP:192.168.10.225
从 - 虚拟机:192.168.11.96
在主数据库创建一个新的用户 用于同步 ‘rep‘;
从数据库我还是用root的用户
2、登录主数据库
创建新用户用于同步
CREATE USER 'rep'@'localhost' IDENTIFIED BY 'hello';
主数据库登录 rep 的账号授予从数据库权限
- GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.11.96'IDENTIFIED BY '123456' WITH GRANT OPTION;
- flush privileges;
- GRANT REPLICATION SLAVE ON *.* TO 'root'@192.168.11.96 IDENTIFIED BY '123456';
- GRANT FILE,SELECT,REPLICATION SLAVE ON *.* TO 'root'@192.168.11.96 IDENTIFIED BY '123456';
备注:如果想要在Slave上有权限执行"LOAD TABLE FROM MASTER" 或 "LOAD DATA FROM MASTER"语句的话,必须授予全局的 FILE 和 SELECT 权限:
GRANT FILE,SELECT,REPLICATION SLAVE ON *.* TO 'root'@192.168.11.96 IDENTIFIED BY '123456';
3、配置主数据master 的my.cnf
- [mysqld]
- #master configure
- server-id = 1
- log-bin=mysql-bin
- binlog-do-db=test
- binlog-ignore-db=mysql
- #master configure
- datadir=/var/lib/mysql
- socket=/var/lib/mysql/mysql.sock
4、备份master的数据库
导出要同步的数据库 这里是test
由于master数据库是Windows的,直接手动导出 ,如果是linux的就方便点。。
在MASTER数据库 主机
- mysql> FLUSH TABLES WITH READ LOCK; //先锁表
- # mysqldump -uroot -pmydb test >e:\mysql\test.sql
- # scp test.sql 192.168.11.96:/tmp/ //注意路径问题
- # mysql -uroot -p123456 test < /tmp/test.sql //记得先建好数据库test
- mysql> UNLOCK TABLES;
- mysql -h192.168.10.225 -urep -phello
- SHOW GRANTS;
- mysql> SHOW GRANTS;
- +-------------------------------------------------------------------------------------------------------------------------------------------+
- | Grants for rep@192.168.11.96 |
- +-------------------------------------------------------------------------------------------------------------------------------------------+
- | GRANT SELECT, FILE, REPLICATION SLAVE ON *.* TO 'rep'@'192.168.11.96' IDENTIFIED BY PASSWORD '*6B4F89A54E2D27ECD7E8DA05B4AB8FD9D1D8B119' |
- +-------------------------------------------------------------------------------------------------------------------------------------------+
- 1 row in set (0.00 sec)
+------------------------+-----------+--------------------+-------------------------+---------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------------+-----------+--------------------+-------------------------+---------------------------+
| mysql-bin.000003 | 2110 | test | mysql | |
+------------------------+-----------+--------------------+-------------------------+---------------------------+
1 row in set
- mysql> CHANGE MASTER TO MASTER_HOST='192.168.11.225',MASTER_USER='rep',MASTER_PASSWORD='hello',MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=2110;
- mysql> start slave;
- mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.10.225
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 1864
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 526
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1864
Relay_Log_Space: 696
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: df35b1ba-2321-11e7-be6c-00e04c12323b
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)
完成!!!!!!!!
有空再跑一遍!!!!
参考http://blog.csdn.net/xluren/article/details/10144165
- mysql 主从复制 主从配置
- mysql 主从配置
- MySQL主从服务器配置
- MYSQL 主从服务器配置
- MySQL主从复制配置
- MYSQL主从服务器配置
- MYSQL 主从服务器配置
- MySQL主从复制配置
- MySQL主从配置
- MySQL互为主从配置
- 配置MySQL主从复制
- MySQL的主从配置
- mysql主从数据库配置
- mysql 主从服务器配置
- mysql 主从配置
- mysql主从数据配置
- MYSQL 主从同步配置
- mysql主从配置
- linux安装nginx
- required a bean of type 'org.hibernate.SessionFactory' that could not be found.
- 项目与团队管理
- Android开发之远程服务[Remote:]通信
- Docker概念
- MYSQL 主从配置
- call与apply
- Java RMI之HelloWorld篇
- 深入java 自定义异常以及常用
- REM转换脚本
- Struts2之form标签的action及namespace属性的组合使用
- hibernate单表,一对多,多对多注解详解
- JSP的四种作用域
- JSTL中foreach标签结合select标签使用