准备
主MySQL
-
修改MySQL配置
# vim /etc/my.cnf [mysqld] server-id=1 log-bin=/data/mysql/bin-log/bin-log
-
创建同步帐户
> GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by '123456';
-
重启MySQL
# /etc/init.d/mysqld restart
-
查询master状态
> show master status; +----------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +----------------+----------+--------------+------------------+-------------------+ | bin-log.000004 | 308 | | | | +----------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)
记下bin-log文件名
bin-log.000004
和bin-log点308
此时不要再操作主MySQL,防止状态值变化
从MySQL
-
创建所需目录
# mkdir /data/mysql/log-relay
-
修改MySQL配置
# vi /etc/my.cnf [mysqld] server-id=2 read_only=1 relay_log=/data/mysql/log-relay/log-relay
-
重启MySQL
# /etc/init.d/mysqld restart
-
连接主MySQL
> change master to master_host='10.10.10.81',master_user='mysync',master_password='123456',master_log_file='mysql-bin.000004',master_log_pos=308;
master_host
主MySQL的IP
master_user
主MySQL的同步账户
master_password
主MySQL的同步账户密码
master_log_file
主MySQL的bin-log文件名
master_log_pos
主MySQL的bin-log点 -
启动复制功能
> start slave;
-
检查复制功能状态
> show slave status \G
Slave_IO_Running
及Slave_SQL_Running
都为YES
表示正常运行