主库服务器环境:
操作系统:Centos6.5
数据库:Mysql5.5
IP: 111.111.111.111
从库服务器环境:
操作系统:Centos6.5
数据库:Mysql5.5
IP:222.222.222.222
1、主库创建同步用户
mysql> grant replication slave, replication client on *.* to backup@'222.222.222.222' identified by '密码';
2、主库配置
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
配置后重启mysql
3、从库配置
log-bin=mysql-bin
binlog_format=mixed
server-id = 2
relay_log = /var/lib/mysql/mysql-relay-bin #mysql数据目录位置,如/data/mysqldata/relay.log
log_slave_updates = 1
read_only = 1 #从库是否可写
配置后重启mysql
4、从库启动slave
mysql> change master to master_host='192.168.1.201',
master_user='repl',
master_password='100301',
master_log_file='mysql-bin.000001',
master_log_pos=0;
从库开启同步
mysql> start slave;
[测试]从服务器连接主库:
mysql -h222.222.222.222 -ubackup -p
|