mysql主从同步:
主库
1)、授权给从数据库服务器
mysql>GRANT REPLICATION SLAVE ON *.* to'rep1'@'192.168.8.11'identified by'test123456';
mysql>FLUSH PRIVILEGES;
2)、修改主库配置文件,开启binlog,并设置server-id,每次修改配置文件后都要重启mysql服务才会生效
vim /etc/my.cnf
在该配置文件[mysqld]下面添加下面内容:
[mysqld]
log-bin=/var/lib/mysql/binlog
server-id=1
binlog-do-db = cmdb
从库
mysql> CHANGE MASTER TO MASTER_HOST='192.168.8.10',
MASTER_PORT=3306,
MASTER_USER='rep1',
MASTER_PASSWORD='test123456',
MASTER_LOG_FILE='binlog.000001',
MASTER_LOG_POS=1304; #后面两个参数的值与主库保持一致