mysql主从同步配置

主:192.168.199.200

从:192.168.199.201

1.主mysql开启binlog功能

/etc/my.cnf #配置文件

[mysqld]
log_bin = /data/mysql/mysql_m-bin #开启binlog

2.重启mysql,后生成日志文件

cat /data/mysql/mysql_m-bin.000001 #把里面记录的日志文件名记录下来等一下从库要用到

3.创建用户并授权

mysql -uroot -p
grant replication slave on *.* to "cs-1"@"192.168.199.%"identified by "wangwei"; 
flush privileges;

4.查看主库id和状态

SHOW VARIABLES LIKE ‘server_id‘; #查看id
SET GLOBAL server_id=1;  #修改id,保证主从库id不同

相关推荐