5、查看主数据库状态
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 | 263 | | |
+------------------+----------+--------------+------------------+
6、配置从数据库
mysql> change master to
-> master_host='192.168.0.202',
-> master_user='sync',
-> master_password='1234.com',
-> master_log_file='mysql-bin.000002',
-> master_log_pos=263;
#Log和pos是master上随机获取的。这段也可以写到my.cnf里面。
7、启动slave同步进程并查看状态
mysql> start slave;
其中Slave_IO_Running 与 Slave_SQL_Running 的值都必须为YES,才表明状态正常。
8、验证主从同步
在主mysql创建数据库abc,再从mysql查看已经同步成功!
mysql> create database abc;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| abc |
| mysql |
| performance_schema |
| test |
+--------------------+
在slave启动报错:
“Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: ‘Could not find first log file name in binary log index file’”
解决:报错的原因主要是slave设置master的二进制文件名或pos值不对应!
先flush logs;清空日志,在查看下主数据库的状态 show master status;看下日志文件名字和position值;
再在slave中,执行:CHANGE MASTER TO MASTER_LOG_FILE=‘二进制日志名’,MASTER_LOG_POS=值;
最后启动同步进程:start slave;