centos6.X mysql 5.1 主主配置
1、配置文件
A库的配置文件:
在 /etc/my.cnf [mysqld] 段 新增: server_id=1 # log_bin 日志路径、格式以及删除时间(30天) log_bin=/var/lib/mysql/mysql-bin binlog_format='MIXED' # ROW STATEMENT MIXED
expire_logs_days=30 # 从主库同步过来的日志路径 relay-log=/var/lib/mysql/relay-bin
B库的配置文件
在 /etc/my.cnf [mysqld] 段 新增: server_id=2 # log_bin 日志路径、格式以及删除时间(30天)
log_bin=/var/lib/mysql/mysql-bin binlog_format='MIXED' # ROW STATEMENT MIXED
expire_logs_days=30
# 从主库同步过来的日志路径
relay-log=/var/lib/mysql/relay-bin
2、A、B上配置同步用户(master配置)
登录数据库
mysql -u root -p
创建创建一个用户。
create user 'repl'@'192.168.122.%' identified by '123456';
在主服务器赋予它 replication slave 权限。
grant replication slave on *.* to 'repl'@'192.168.122.%';
3、在A、B上查看当前binlog文件名和position
A、
mysql> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000006 | 106 | | | +------------------+----------+--------------+------------------+
B、
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 | 112 | | |
+------------------+----------+--------------+------------------+
4、分别配置A、B上的Slave配置
A、192.168.122.37 为B的 IP
CHANGE MASTER TO MASTER_HOST='192.168.122.37', MASTER_USER='repl', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000003', MASTER_LOG_POS=112;
START SLAVE;
show slave status\G;
查看下面两项都是Yes说明配置正常。
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
B、192.168.122.36 为 A 的 IP
CHANGE MASTER TO MASTER_HOST='192.168.122.36', MASTER_USER='repl', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000006', MASTER_LOG_POS=106;
START SLAVE;
show slave status\G;
查看下面两项都是Yes说明配置正常。
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
据说指定复制哪些表参数replicate-do-db会有问题,要用replicate-wild-do-table和Replicate-Ignore-Table代替 参见:
http://blog.sina.com.cn/s/blog_747f4c1d0102w9pp.html