0

0

Mysql 5.5 replication多数据库主从备份Master-Slave配置总结_MySQL

php中文网

php中文网

发布时间:2016-06-01 13:29:02

|

1206人浏览过

|

来源于php中文网

原创

bitsCN.com

mysql 5.5 replication多数据库主从备份master-slave配置总结

 

MyMap AI
MyMap AI

使用AI将想法转化为图表

下载

配置Mysql server 5.5 的双机备份,也就是master-slave模式。本例子还是一个多database复制的情况。

 

现在有两个database在同一台mysql server,也就是master,各自有自己的user访问和操作,用于不同的应用程序。这两个database都要通过replication配置,实时复制到另一台mysql server上,也就是slave。

 

配置步骤:

 

1. 从master上到处现有的数据

mysqldump -R -E -uroot -p ADB > masteradb.sql;mysqldump -R -E -uroot -p BDB > masterbdb.sql;

 

 

2. 为master和slave定制配置文件/etc/my.cnf,然后启动mysql

 

vi /etc/my.cnf

 

###详细内容见附录

service mysql restart

 

3. 在slave上创建database.

create database ADB;

create database BDB;

 

4. 在master和slave上配置user和privilege;

 

GRANT ALL PRIVILEGES ON ADB.* TO usera@`%` IDENTIFIED BY 'pass' WITH GRANT OPTION;GRANT ALL PRIVILEGES ON ADB.* TO usera@`localhost` IDENTIFIED BY 'pass' WITH GRANT OPTION;GRANT ALL PRIVILEGES ON BDB.* TO userb@`%` IDENTIFIED BY 'pass' WITH GRANT OPTION;GRANT ALL PRIVILEGES ON BDB.* TO userb@`localhost` IDENTIFIED BY 'pass' WITH GRANT OPTION;flush privileges;

 

 

5. 在master上配置用于数据复制的user和privilege;

 

grant SUPER ON *.* TO 'auser'@'%' IDENTIFIED BY 'pass' WITH GRANT OPTION;grant SUPER ON *.* TO 'buser'@'%' IDENTIFIED BY 'pass' WITH GRANT OPTION;GRANT SELECT ON mysql.proc TO 'auser'@'%' IDENTIFIED BY 'pass' WITH GRANT OPTION;GRANT SELECT ON mysql.proc TO 'buser'@'%' IDENTIFIED BY 'pass' WITH GRANT OPTION;GRANT REPLICATION SLAVE ON *.* TO repluser IDENTIFIED BY 'pass';flush privileges;

 

 

6. 在master上运行下列命令,得到master的状态,包含binlog的文件名和当前位置

mysql> show master status;+------------------+----------+--------------------------------+------------------+| File             | Position | Binlog_Do_DB                   | Binlog_Ignore_DB |+------------------+----------+--------------------------------+------------------+| mysql-bin.000001 |   000173| ADB,BDB |                  |+------------------+----------+--------------------------------+------------------+1 row in set (0.02 sec)

 

 

7. 在slave配置复制来源,包括hostname,user,password,binlog文件名,位置。

CHANGE MASTER TO MASTER_HOST='10.224.106.225', MASTER_USER='repluser', MASTER_PASSWORD='pass', master_log_file='mysql-bin.000001', master_log_pos=173;start slave;

 

 

8. 运行下列命令查看slave的当前状态。

 

show slave status/G

 

结果出现

 

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

 

表示数据同步复制已经成功运行。

 

提示:如果show slave status/G 出现了错误,运行下列命令跳过,在重启slave

SET GLOBAL SQL_SLAVE_SKIP_COUNTER =100;start slave;show slave status/G;stop slave;SET GLOBAL SQL_SLAVE_SKIP_COUNTER =0;start slave;

 

 

附录:

 

master my.cnf配置

 

[plain] [client]  port            = 3306  socket          = /var/lib/mysql/mysql.sock      [mysqld]  port            = 3306  socket          = /var/lib/mysql/mysql.sock  skip-external-locking  key_buffer = 384M  max_allowed_packet = 32M  table_open_cache = 5120  key_buffer_size = 64M  sort_buffer_size = 512M  net_buffer_length = 8K  read_buffer_size = 16M  read_rnd_buffer_size = 128M  myisam_sort_buffer_size = 128M    query_cache_size = 256M  tmp_table_size = 128M  max_heap_table_size = 128M  thread_concurrency = 8  max_connections=500  group_concat_max_len=1048576    max_sp_recursion_depth=255      slow_query_log_file=/spare/mysql/slow_queries.log  long_query_time = 5        binlog_cache_size = 2M  join_buffer_size = 32M  thread_cache_size = 16  query_cache_limit = 2M  transaction_isolation = REPEATABLE-READ  log-bin=mysql-bin  auto_increment_increment = 2  auto_increment_offset = 1  server-id       = 1    binlog-do-db            = ADB  binlog-do-db            = BDB    log_slave_updates = 1  relay-log=RELAY_LOCALHOST-relay-bin        innodb_data_home_dir = /spare/mysql/  innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend  innodb_log_group_home_dir = /spare/mysql/    innodb_additional_mem_pool_size = 16M    innodb_buffer_pool_size = 8G  innodb_thread_concurrency = 16    innodb_flush_log_at_trx_commit = 2    innodb_log_buffer_size = 8M    innodb_log_file_size = 250M    max_binlog_size=100M  expire_logs_days=3  sync_binlog=1 #Ensure all writes to binary are flushed to disk in a timely manner  binlog-format=ROW    [mysqldump]  quick  max_allowed_packet = 256M    [mysql]  no-auto-rehash    [isamchk]  key_buffer = 256M  sort_buffer_size = 256M  read_buffer = 2M  write_buffer = 2M    [myisamchk]  key_buffer = 256M  sort_buffer_size = 256M  read_buffer = 2M  write_buffer = 2M    [mysqlhotcopy]  interactive-timeout  slave my.cnf配置[plain] [client]  port            = 3306  socket          = /var/lib/mysql/mysql.sock      [mysqld]  port            = 3306  socket          = /var/lib/mysql/mysql.sock  skip-external-locking  key_buffer = 384M  max_allowed_packet = 32M  table_open_cache = 5120  key_buffer_size = 64M  sort_buffer_size = 512M  net_buffer_length = 8K  read_buffer_size = 16M  read_rnd_buffer_size = 128M  myisam_sort_buffer_size = 128M    query_cache_size = 256M  tmp_table_size = 128M  max_heap_table_size = 128M  thread_concurrency = 8  max_connections=500  group_concat_max_len=1048576    max_sp_recursion_depth=255      slow_query_log_file=/spare/mysql/slow_queries.log  long_query_time = 5        binlog_cache_size = 2M  join_buffer_size = 32M  thread_cache_size = 16  query_cache_limit = 2M  transaction_isolation = REPEATABLE-READ  log-bin=mysql-bin  auto_increment_increment = 2  auto_increment_offset = 1   # the slave offset keep same as master  server-id       = 2    replicate-do-db            = ADB  replicate-do-db            = BDB    log_slave_updates = 1  relay-log=RELAY_LOCALHOST-relay-bin        innodb_data_home_dir = /spare/mysql/  innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend  innodb_log_group_home_dir = /spare/mysql/    innodb_additional_mem_pool_size = 16M  innodb_autoextend_increment = 256M  innodb_buffer_pool_size = 8G  innodb_thread_concurrency = 16    innodb_flush_log_at_trx_commit = 2  innodb_log_buffer_size = 8M  ####innodb_log_buffer_size = 32M  innodb_log_file_size = 250M      max_binlog_size=100M  expire_logs_days=3  sync_binlog=1 #Ensure all writes to binary are flushed to disk in a timely manner  binlog-format=ROW    [mysqldump]  quick  max_allowed_packet = 256M    [mysql]  no-auto-rehash    [isamchk]  key_buffer = 256M  sort_buffer_size = 256M  read_buffer = 2M  write_buffer = 2M    [myisamchk]  key_buffer = 256M  sort_buffer_size = 256M  read_buffer = 2M  write_buffer = 2M    [mysqlhotcopy]  interactive-timeout  

 


bitsCN.com

相关专题

更多
Word 字间距调整方法汇总
Word 字间距调整方法汇总

本专题整合了Word字间距调整方法,阅读下面的文章了解更详细操作。

2

2025.12.24

任务管理器教程
任务管理器教程

本专题整合了任务管理器相关教程,阅读下面的文章了解更多详细操作。

2

2025.12.24

AppleID格式
AppleID格式

本专题整合了AppleID相关内容,阅读专题下面的文章了解更多详细教程。

0

2025.12.24

csgo视频观看入口合集
csgo视频观看入口合集

本专题整合了csgo观看入口合集,阅读下面的文章了知道更多入口地址。

29

2025.12.24

yandex外贸入口合集
yandex外贸入口合集

本专题汇总了yandex外贸入口地址,阅读下面的文章了解更多内容。

58

2025.12.24

添加脚注通用方法
添加脚注通用方法

本专题整合了添加脚注方法合集,阅读专题下面的文章了解更多内容。

1

2025.12.24

重启电脑教程汇总
重启电脑教程汇总

本专题整合了重启电脑操作教程,阅读下面的文章了解更多详细教程。

3

2025.12.24

纸张尺寸汇总
纸张尺寸汇总

本专题整合了纸张尺寸相关内容,阅读专题下面的文章了解更多内容。

5

2025.12.24

Java Spring Boot 微服务实战
Java Spring Boot 微服务实战

本专题深入讲解 Java Spring Boot 在微服务架构中的应用,内容涵盖服务注册与发现、REST API开发、配置中心、负载均衡、熔断与限流、日志与监控。通过实际项目案例(如电商订单系统),帮助开发者掌握 从单体应用迁移到高可用微服务系统的完整流程与实战能力。

1

2025.12.24

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
动力节点mysql基础视频教程
动力节点mysql基础视频教程

共86课时 | 18万人学习

PostgreSQL 教程
PostgreSQL 教程

共48课时 | 5.9万人学习

Django 教程
Django 教程

共28课时 | 2.4万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

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