主机操作系统:RedHatEnterprise Linux 6 数据库版本 前提:MYSQL数据库正常启动 假设两台主机地址分别为:
ServA:192.168.18.112 ServB:192.168.18.114
注意:操作前,全文查找替换,将server A、B替换成实际IP
2、配置同步账号
在ServA上增加一个ServB可以登录的帐号: mysql -uroot -p123456
grant all privileges on *.* tolwh@192.168.18.114> 在ServB上远程登录查看192.168.18.114使用lwh这个账号密码为123456登录上去拥有全部权限 mysql -h 192.168.18.112 -ulwh -p123456
在ServB上增加一个ServA可以登录的帐号: mysql -uroot -p123456
grant all privileges on *.* tolwh@192.168.18.114> 在ServA上远程登录查看192.168.18.112使用lwh这个账号密码为123456登录上去拥有全部权限
假设以ServA为主服务器,在ServB上重启mysql: service mysqld restart 在ServB上用root用户登录mysql,执行: Mysql> stop slave; Mysql> load data from master; Mysql> start slave; 在ServA上重启mysql: service mysqld restart
同步过程中出现下列问题 mysql> show slave status\G; *************************** 1. row*************************** Slave_IO_State: Master_Host: 192.168.18.112 Master_User: tongbu Master_Port: 3306 Connect_Retry: 30 Master_Log_File: Read_Master_Log_Pos: 4
> Relay_Log_Pos: 4 Relay_Master_Log_File: Slave_IO_Running: No Slave_SQL_Running: Yes Replicate_Do_DB: lwh Replicate_Ignore_DB: 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: 0
> 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: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 1236 Last_IO_Error: Got fatal error 1236 from master when reading dat a from binarylog: 'Binary log is not open' Last_SQL_Errno: 0 Last_SQL_Error: 1 row in set (0.00 sec)
[root@luowenhao ~]# tail/var/log/mysqld.log 140921 0:02:42 [Note] /usr/libexec/mysqld: ready for connections. Version: '5.1.52-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
140921 0:02:42 [Note] Slave SQL thread initialized, starting replication in log'FIRST' at position 0,> 140921 0:02:42 [Note] Slave I/O thread: connected to master'tongbu@192.168.18.112:3306',replication started in log 'FIRST' at position 4 140921 0:02:42 [ERROR] Error reading packet from server: Binary log is not open( server_errno=1236) 140921 0:02:42 [ERROR] Slave I/O: Got fatal error1236 from master when reading data from binary log: 'Binary log is not open',Error_code: 1236 翻译大概是有致命错误1236从二进制日志读取数据时从主:“二进制日志不开放,下面就进行了刷新日志 140921 0:02:42 [Note] Slave I/O thread exiting, read up to log 'FIRST',position 4
140921 2:15:04 [Note] Error reading>
140921 2:16:06 [Note] Slave SQL thread initialized, starting replication in log'FIRST' at position 0,> 140921 2:16:06 [Note] Slave I/O thread: connected to master'tongbu@192.168.18.112:3306',replication started in log 'FIRST' at position 4