1、yum安装mysql服务
2、Master上修改my.cnf文件
vi /etc/my.cnf
将下面内容添加到[mysqld]模块中
server-id = 1 #master
log-bin = mysql-bin #开启binlog日志,mysql-bin为log名称
binlog-do-db = kefu #同步的数据库名,每个需要同步的库写一行配置
binlog-ignore-db = mysql #不同步的数据库,每个不需要同步的库写一行配置
binlog-ignore-db = test #不同步的数据库,每个不需要同步的库写一行配置
3、重启mysql master服务
service mysqld restart
4、授权slave库,进入mysql:
mysql>grant replication slave on *.* to root@'10.13.0.157' identified by 'root156';
mysql>flush privileges;
5、查看主库状态,确认binlog开启,能够查询master状态
mysql>show variables like '%bin%';
log_bin状态应该为ON,如果log-bin = mysql-bin配置未添加或没有添加到[mysqld]位置中,则改状态为OFF
mysql>show master status;
显示如下信息说明正常,slave需要File、Position信息
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 106 | kefu | mysql,test |
+------------------+----------+--------------+------------------+
6、Slave上修改my.cnf文件
vi /etc/my.cnf
将下面内容添加到[mysqld]模块中
server-id = 2
relay-log = relaylog
7、重启mysql slave
service mysqld restart
8、停slave库,连接主库
mysql>slave stop;
mysql>change master to master_host='10.13.0.156',master_user='root',master_password='root156',master_log_file='mysql-bin.000002',master_log_pos=106;
如果出现ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log报错,请删除master.info
rm /var/lib/mysql/master.info
9、查看mysal slave状态
mysql>show slave status \G
下面状态为yes表示主从同步完成
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
阅读(741) | 评论(0) | 转发(0) |