方案描述:
Mysql搭建主从同步来保证高可用模式
搭建步骤
配置两台mysql服务器
(主服务器为MASTER|192.168.99.233)(从服务器为SLAVE|192.168.99.243)
Master
- 修改/etc/my.cnf文件
3. 重启mysql数据库
4. 进入MASTER数据库,为MASTER创建复制用户
Create user 用户 identified by ‘密码’;
5. 赋予用户权限
Grant replication slave on . to ‘用户’@‘IP地址(SLAVE)’ identified by ‘密码’;
Flush privileges;
6. 查看MASTER的状态
Show master status;
Slave
1.修改/etc/my.cnf文件
2. 重启mysql数据库
3.配置SLAVE数据库
Change master to
Master_host = ‘192.168.99.233’ ,
Master_user = ‘用户’,
Master_password = ‘密码’,
Master_port = 3306,
Master_log_file = ‘mysql-bin.000001’,
Master_log_pos = 845,
Master_retry_count = 60,
Master_heartbeat_period = 10000;
#show master status得到File和Position
#Master_log_file = ‘mysql-bin.000001’,(与主库的File保持一致)
#Master_log_pos = 845,(与主库的Position保持一致)
4.启动SLAVE库的slave进程
Start slave;
5. 查看是否同步成功