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

时间:2022-04-02 08:36:36

配置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配置

[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配置

[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

Mysql 5.5 replication 多数据库主从备份Master-Slave配置总结的更多相关文章

  1. MySQL5.6 数据库主从(Master/Slave)同步安装与配置详解

    .安装环境 .基本环境配置 .Master的配置 .Slave的配置 .添加需要同步的从库Slave .真正的测试 安装环境 1 操作系统 :CentOS 6.5 2 数据库版本:MySQL 5.6. ...

  2. Percona备份mysql全库及指定数据库(完整备份与增量备份)

    Percona Xtrabackup备份mysql全库及指定数据库(完整备份与增量备份) Xtrabackup简介 Percona XtraBackup是开源免费的MySQL数据库热备份软件,它能对I ...

  3. MySQL数据库主从同步安装与配置总结

    MySQL的主从同步是一个很成熟的架构,优点为: ①在从服务器可以执行查询工作(即我们常说的读功能),降低主服务器压力: ②在从主服务器进行备份,避免备份期间影响主服务器服务: ③当主服务器出现问题时 ...

  4. Percona Xtrabackup备份mysql全库及指定数据库(完整备份与增量备份)

    原文地址:http://www.tuicool.com/articles/RZRnq2 Xtrabackup简介 Percona XtraBackup是开源免费的MySQL数据库热备份软件,它能对In ...

  5. redis的主从机制 master&slave

    转载自:https://www.cnblogs.com/qwangxiao/p/9733480.html 一:master&slave的解释? master&slave就是主从复制,主 ...

  6. mysql数据库主从备份

    近期实验室总是不给通知的就停电,导致我们在不停的恢复服务.在某一个断电的过程中,发现我们的项目管理工具redmine的硬盘挂掉了..因为是部署在虚拟机上的,也没做冗余,数据就丢了..于是反思,我们的m ...

  7. mariadb主从备份

    mariadb主从备份 master主库配置 停止mariadb systemctl stop mariadb 修改配置文件my.conf vim /etc/my.cnf [mysqld] serve ...

  8. mysql主从备份及常见问题处理

    1.mysql主从备份基本原理 mysql支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.mysql复制基于主服务器在二进制日志中跟踪所有对数据库的更改(更新 ...

  9. 使用percona-xtrabackup工具对mysql数据库的备份方案

    使用percona-xtrabackup工具对mysql数据库的备份方案 需要备份mysql的主机 172.16.155.23存放备份mysql的主机 172.16.155.22 目的:将155.23 ...

随机推荐

  1. AngularJS向指令传递数据

    我今天要实现的功能是利用AngularJS来完成客户端过滤器. list.html页面主要代码如下: ...... <div class='tj_con_tr_ipt' ng-init=&quo ...

  2. myeclipse WIN7下设置字体列表中无Courier New

    到"C:\Windows\Fonts"下找到对应的字体,单击,选择上面的显示 然后就可以在eclicpse字体设置里面看到Courier New项了: Eclipse字体设置方法: ...

  3. jQuery中的siblings

    所谓siblings,英文翻译就是兄弟节点.那么故名思意,就是拿到某元素的兄弟节点(不包括自己). <html> <head> <script type="te ...

  4. Orcale安装完成后 em管理、性能无法登陆 报:没有找到主机

    先在我的电脑环境变量中加入oracle_sid=orcl 在Orcale主目录中查找emd.properties 文件修改(时间格式) agentTZRegion=GMT agentTZRegion= ...

  5. python 3&period;5 猜数字游戏

    #!/usr/bin/env python #encoding: utf-8 number = 88 for i in range(1,6): num = int(input('gusee numbe ...

  6. 结对编程1 (四则运算基于GUI)

    https://git.coding.net/Luo_yujie/sizeyunsuan.app.git 201421123034 201421123032 1. 需求分析 这次作业新引用了语言选择, ...

  7. java中子类继承父类程序执行顺序问题

    Java中,new一个类的对象,类里面的静态代码块.非静态代码.无参构造方法.有参构造方法.类的一般方法等部分,它们的执行顺序相对来说比较简单,用程序也很容易验证.比如新建一个测试父类. public ...

  8. android 缩放平移自定义View 显示图片

    1.背景 现在app中,图片预览功能肯定是少不了的,用户基本已经形成条件反射,看到小图,点击看大图,看到大图两个手指开始进行放大,放大后,开始移动到指定部位~~~ 我相信看图的整个步骤,大家或者说用户 ...

  9. MySQL:基础知识

    基础知识 一.软件的生命周期 软件定义 软件开发 软件使用与维护 二.数据(Data) 1.定义 描述客观事物特征或性质的某种符号,经过数字化处理存储在计算机 2.数据独立性 物理独立性:指用户的应用 ...

  10. 【WPF】退出应用时的提示弹窗

    需求:按MainWindow右上角的[X]想要退出软件时,弹窗提示是否确定要退出. 主界面(ShellWindow)的前台给主界面窗体添加两个事件:Closing和Closed <Window ...