MySQL 互为主备的简单搭建

php中文网
发布: 2016-06-07 17:28:16
原创
1246人浏览过

MySQL 互为主备的简单搭建 192.168.190.128《====》192.168.190.129 master----》slave slave《----master 1.在master 128 上配置

mysql 互为主备的简单搭建

192.168.190.128《====》192.168.190.129
 master----》slave
 slave《----master
 
1.在master 128 上配置my.cnf文件,添加下列参数:
 server-id=1
 log-bin=mysql-bin
 log-salve-updates
 sync_binlog=1
 auto_increment_increment=2
 auto_increment_offset=1
 
 重新启动mysql
 [root@calvin1 ~]# /etc/init.d/mysqld start
 Starting MySQL:  [  OK  ]
 [root@calvin1 ~]# mysql -u root -p123456
 Welcome to the MySQL monitor.  Commands end with ; or \g.
 Your MySQL connection id is 6
 Server version: 5.0.77-log Source distribution
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql> show databases;
 +--------------------+
 | Database          |
 +--------------------+
 | information_schema |
| calvin            |
| calvin2            |
| mysql              |
| sampdb            |
| test              |
| testdb            |
+--------------------+
 7 rows in set (0.00 sec)
 

2.在master 129 上配置my.cnf文件,,添加下列参数:
 server-id=2
 log-bin=mysql-bin
 log-salve-updates
 sync_binlog=1
 auto_increment_increment=2
 auto_increment_offset=2
 
重新启动mysql
 [root@calvin2 ~]# /etc/init.d/mysqld start
 Starting MySQL:  [  OK  ]
 [root@calvin2 ~]# mysql -u root -p123456
 Welcome to the MySQL monitor.  Commands end with ; or \g.
 Your MySQL connection id is 7
 Server version: 5.0.77-log Source distribution
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
 
mysql> show databases;
 +--------------------+
 | Database          |
 +--------------------+
 | information_schema |
| calvin            |
| calvin2            |
| mysql              |
| sampdb            |
| test              |
| testdb            |
+--------------------+
 7 rows in set (0.00 sec)
 

3.在在master 128上创建复制账号:
mysql> grant replication slave,file on *.* to mysync@'192.168.190.129' identified by '123456';
 Query OK, 0 rows affected (0.00 sec)
 
mysql> flush privileges;
 Query OK, 0 rows affected (0.00 sec)
 
对所有表添加只读锁:
 mysql> flush tables with read lock;
 Query OK, 0 rows affected (0.00 sec)
 
查看master二进制文件,pos号:
 mysql> show master status\G;
 *************************** 1. row ***************************
            File: mysql-bin.000004
        Position: 906
    Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)
 
ERROR:
No query specified
 
mysql> unlock tables;
 Query OK, 0 rows affected (0.00 sec)
 
mysql> stop slave;
 Query OK, 0 rows affected, 1 warning (0.00 sec)
 

4.在在master 129上创建复制账号:
 mysql> grant replication slave,file on *.* to mysync@'192.168.190.128' identified by '123456';
 Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
 Query OK, 0 rows affected (0.00 sec)
 
对所有表添加只读锁:
 mysql> flush tables with read lock;
 Query OK, 0 rows affected (0.00 sec)
 
查看master二进制文件,pos号:
 mysql> show master status\G;
 *************************** 1. row ***************************
            File: mysql-bin.000001
        Position: 318
    Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)
 
ERROR:
No query specified
 
mysql> unlock tables;
 Query OK, 0 rows affected (0.00 sec)
 
mysql> stop slave;
 Query OK, 0 rows affected (0.00 sec)
 
 
 
5.修改同步参数:
 根据第3步读取的二进制文件和pos号,配置master 128的同步参数:
 mysql> change master to
    -> master_host='192.168.190.129',
    -> master_user='mysync',
    -> master_password='123456',
    -> master_log_file='mysql-bin.000001',
    -> master_log_pos=318;
 Query OK, 0 rows affected (0.01 sec)
 
mysql> start slave;
 Query OK, 0 rows affected (0.00 sec)
 
根据第4步读取的二进制文件和pos号,配置master 129的同步参数:
 mysql> change master to
    -> master_host='192.168.190.128',
    -> master_user='mysync',
    -> master_password='123456',
    -> master_log_file='mysql-bin.000004',
    -> master_log_pos=906;           
Query OK, 0 rows affected (0.01 sec)
 
mysql> start slave;
 Query OK, 0 rows affected (0.01 sec)
 

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号