前言 XtraBackup 是 percona 出的一款mysql备份工具,可以使用它对mysql进行高效备份 下面分享一下使用 XtraBackup 创建mysql slave的基础操作,详细可以参阅...官方文档 Tip: 当前版本 Percona XtraBackup 2.2 ---- 概要 ---- 准备slave软件环境 下载安装percona repo [root@slave-test src...src]# ls percona-release-0.1-3.noarch.rpm [root@slave-test src]# rpm -ivh percona-release-0.1-3.noarch.rpm...####### [100%] 1:percona-release ########################################### [100%] [root@slave-test...src]# 可以在系统中进行一下检查 [root@slave-test src]# rpm -qlp percona-release-0.1-3.noarch.rpm warning: percona-release
状况描述: 今天登录一个MySQL数据库slave节点主机发现/var/lib/mysql下存放大量的mysql-relay-bin文件,最早的文件创建日期甚至是2018年,我记得在slave库同步完master...的日志操作记录后,会删除这些文件(默认设置不会删除,我记错了),于是便查看了slave库的状态,发现如下报错: mysql> show slave status\G; *****************...: 我在master节点上删除了名称为mysql-bin.00007格式的文件,其中包括mysql-bin.000075,因此,slave库找不到该文件,无法同步。...,导入该备份文件 mysql -u root -p < bak.master.sql 7)在slave节点上,重新指定读master日志的位置: slave stop; CHANGE MASTER...总结: 清理文件时,要注意mysql-bin文件在master、slave节点日志读取和写的位置啊!
\ -v $(pwd)/mysql-master.cnf:/etc/mysql/conf.d/mysql-master.cnf \ mysql:8.0 \ --log-bin=my 启动Slave...启动Slave: docker run -d --name mysql-slave-1 \ -e MYSQL_ROOT_PASSWORD=my_root_password \ -p 3308:3306...\ -v $(pwd)/mysql-slave-1.cnf:/etc/mysql/conf.d/mysql-slave-1.cnf \ mysql:8.0 \ --skip-log-bin...最后正式启动Slave: mysql> START SLAVE; 验证 到Slave上看看my_database是否存在: $ docker exec -it mysql-slave-1 mysql -..._1 mysql -u root -p # 连接Slave $ docker exec -it mysql-repl_mysql-slave_1 mysql -u root -p 并且CHANGE MASTER
最近在部署MySQL主从复制架构的时候,碰到了"Last_IO_Error: Fatal error: The slave I/O thread stops because master and...slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work."...1、错误消息 mysql> show slave staus; Last_IO_Error: Fatal error: The slave I/O thread stops because master...and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work. 2...| Value | +---------------+-------+ | server_id | 33 | +---------------+-------+ slave_mysql
在MySQL复制环境中,我们通常只根据 Seconds_Behind_Master 的值来判断SLAVE的延迟。这么做大部分情况下尚可接受,但并不够准确,而应该考虑更多因素。...*************************** Slave_IO_State: Waiting for master to send event *** Master_Log_File: mysql-bin...Relay_Master_Log_File: mysql-bin.000327 Slave_IO_Running: Yes Slave_SQL_Running: Yes *** Skip_Counter....000009 | 1073742063 | | mysql-bin.000010 | 107374193 | +------------------+--------------+ 而在 SLAVE...: mysql-bin.000009 Slave_IO_Running: Yes Slave_SQL_Running: Yes *** Exec_Master_Log_Pos: 654409041 *
-10-12_15-24-06]# cat xtrabackup_binlog_info mysql-bin.000009 1509223 [root@slave-test 2015-10-12_15...-06]# 在合适的位置创建一个空文件夹,用来存放数据文件 [root@slave-test lib]# mv mysql/ mysql.old [root@slave-test lib]# ln -...s /data/mysql/ /var/lib/mysql [root@slave-test lib]# cd /var/lib/mysql [root@slave-test mysql]# ls [...root@slave-test mysql]# [root@slave-test ~]# ll /var/lib/mysql lrwxrwxrwx 1 root root 12 Oct 12 15:00.../var/lib/mysql -> /data/mysql/ [root@slave-test ~]# ll /data/mysql/ total 0 [root@slave-test ~]# Note
在MySQL复制环境中,我们通常只根据 Seconds_Behind_Master 的值来判断SLAVE的延迟。这么做大部分情况下尚可接受,但并不够准确,而应该考虑更多因素。...************************* Slave_IO_State: Waiting for master to send event *** Master_Log_File: mysql-bin...Relay_Master_Log_File: mysql-bin.000327 Slave_IO_Running: Yes Slave_SQL_Running: Yes *** Skip_Counter....000009 | 1073742063 | | mysql-bin.000010 | 107374193 | +------------------+--------------+ 而在SLAVE上执行...: mysql-bin.000009 Slave_IO_Running: Yes Slave_SQL_Running: Yes *** Exec_Master_Log_Pos: 654409041 **
以MySQL5.7.19为例,部分重要的地方用红色标注了。...>show slave status\G *************************** 1. row *************************** Slave_IO_State... Master_UUID: e00b1731-a383-11e7-ada1-000c29c99d23 Master_Info_File: mysql.slave_master_info...补充,RESET命令的用法: 1 RESET MASTER: 删除全部的binlog文件,重置mysql.index文件为空,然后重新生成一个binlog文件。...4 RESET SLAVE ALL: 是在reset slave的基础上,进一步重置了chagne master to的参数。这样的话,show slave status\G就没有显示。
稳定后的状态 mysql> show slave status\G *************************** 1. row ***************************...Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin...Relay_Log_Pos: 160542 Relay_Master_Log_File: mysql-bin.000009 Slave_IO_Running...Master_UUID: adf0b5b2-26fb-11e5-8bba-0024213a7622 Master_Info_File: /var/lib/mysql...: Slave has read all relay log; waiting for the slave I/O thread to update it Master_Retry_Count
到此salve的软件环境就已经准备好了 ---- 注意事项 1.slave上的数据存储位置有足够的空间,如果没有最好链接到一个有空间的位置 2.slave上使用master的配置文件,可以将有些大内存使用参数酌情改小...server with DSN 'dbi:mysql:;mysql_read_default_file=/etc/my.cnf;mysql_read_default_group=xtrabackup'...: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/etc/my.cnf;mysql_read_default_group...server as DBD::mysql module is not installed at /usr/bin/innobackupex line 3006....[root@master-qa ~]# rpm -qa | grep -i dbd perl-DBD-SQLite-1.27-3.el6.x86_64 perl-DBD-MySQL-4.013-3.el6
执行同步 [root@slave-test mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor....mysql> show slave status\G Empty set (0.00 sec) mysql> CHANGE MASTER TO MASTER_HOST='192.168.1.66',...; Query OK, 0 rows affected, 2 warnings (0.46 sec) mysql> show slave status\G **********************...Relay_Log_Pos: 4 Relay_Master_Log_File: mysql-bin.000009 Slave_IO_Running...> start slave; Query OK, 0 rows affected (0.10 sec) mysql> show slave status\G *********************
ORACLE MySQL 5.6版本开始支持多线程复制,配置选项 slave_parallel_workers 即可实现在slave上多线程并发复制。...另一个重要原因是,传统的MySQL复制是异步(asynchronous)的,也就是说在master提交完后,才在slave上再应用一遍,并不是真正意义上的同步。...因此,严格意义上讲,MySQL复制不能叫做MySQL同步(处女座的面试官有可能会在面试时把说成MySQL同步的一律刷掉哦)。...综合这两个主要原因,slave想要尽可能及时跟上master的进度,可以尝试采用以下几种方法: 采用MariaDB发行版,它实现了相对真正意义上的并行复制,其效果远比ORACLE MySQL好的很多。...库都被挂起,可参考案例:mysql主键的缺少导致备库hang; 应用程序端多做些事,让MySQL端少做事,尤其是和IO相关的活动,例如:前端通过内存CACHE或者本地写队列等,合并多次读写为一次,甚至消除一些写请求
可知 perl-DBD-MySQL 已经安装了,和报错不符合 解决办法: 重装 perl-DBD-MySQL [root@master-qa ~]# yum list all | grep perl-DBD-MySQL...perl-DBD-MySQL.x86_64 4.013-3.el6 @base [root@master-qa ~]...# yum reinstall perl-DBD-MySQL.x86_64 Loaded plugins: fastestmirror, refresh-packagekit, security...-4.013-3.el6.x86_64 --> Processing Dependency: libmysqlclient.so.16()(64bit) for package: perl-DBD-MySQL...=========================================================================== Reinstalling: perl-DBD-MySQL
恢复数据库 [root@slave-test fullbackup]# innobackupex --copy-back /data/fullbackup/2015-10-12_15-24-06/.../xtrabackup_binlog_pos_innodb' innobackupex: Creating directory '/var/lib/mysql/bhdw_qa' innobackupex...data/fullbackup/2015-10-12_15-24-06' innobackupex: back to original InnoDB data directory '/var/lib/mysql.../' innobackupex: Copying '/data/fullbackup/2015-10-12_15-24-06/ibdata1' to '/var/lib/mysql/ibdata1'...[root@slave-test fullbackup]# echo $? 0 [root@slave-test fullbackup]#
恢复完后, datadir 里也有一个位置文件 [root@slave-test mysql]# cat /data/mysql/xtrabackup_binlog_pos_innodb mysql-bin....000009 1509223 [root@slave-test mysql]# cat /data/mysql/xtrabackup_info uuid = 3cf59860-70b3-11e5-95db...76232242511 partial = N incremental = N format = file compact = N compressed = N encrypted = N[root@slave-test...mysql]# ---- 修改数据权限 [root@slave-test mysql]# chown -R mysql:mysql /var/lib/mysql [root@slave-test...mysql]# [root@slave-test data]# chown -R mysql:mysql /data/mysql/ [root@slave-test data]#
启动mysql,设定密码 [root@slave-test src]# /etc/init.d/mysql start Starting MySQL (Percona Server)....[ OK ] [root@slave-test src]# /usr/bin/mysqladmin -u root password 'xxxxx...[root@slave-test src]# mysql -u root -p Enter password: Welcome to the MySQL monitor....mysql> mysql> mysql> show databases; +--------------------+ | Database | +---------------...-------------------+ 4 rows in set (0.00 sec) mysql>
启动数据库 [root@slave-test data]# /etc/init.d/mysql start Starting MySQL (Percona Server)......[ OK ] [root@slave-test data]# [root@slave-test data]# mysql -u root -p...mysql> show slave status\G Empty set (0.00 sec) mysql> ---- 创建复制用户 在master上创建一个复制用户 mysql> grant replication...slave,replication client on *.* to repl@'192.168.1.%' identified by 'xxxxxx' ; Query OK, 0 rows affected...(0.04 sec) mysql> flush privileges; Query OK, 0 rows affected (0.08 sec) mysql>
安装percona-xtrabackup [root@slave-test src]# yum -y install percona-xtrabackup.x86_64 Loaded plugins...Package percona-xtrabackup.x86_64 0:2.2.12-1.el6 will be installed --> Processing Dependency: perl(DBD::mysql...package: percona-xtrabackup-2.2.12-1.el6.x86_64 --> Running transaction check ---> Package perl-DBD-MySQL.x86...Development Team Package: percona-release-0.1-3.noarch (installed) From...[root@slave-test src]#
准备数据 [root@slave-test ~]# /usr/bin/innobackupex --apply-log /data/fullbackup/2015-10-12_15-24-06/...mysqld" --prepare --target-dir=/data/fullbackup/2015-10-12_15-24-06 xtrabackup version 2.2.12 based on MySQL...replication slave the last master binlog file InnoDB: position 0 221675975, file name mysql-bin.000238...InnoDB: Last MySQL binlog file position 0 1509223, file name mysql-bin.000009 InnoDB: 128 rollback segment...[root@slave-test ~]# echo $? 0 [root@slave-test ~]#
安装mysql [root@slave-test src]# yum install Percona-Server-server-56 Loaded plugins: fastestmirror, refresh-packagekit...following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h slave-test...password 'new-password' Alternatively you can run: /usr/bin/mysql_secure_installation which will...SONAME 'libfnv1a_udf.so'" mysql -e "CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'libfnv_udf.so'" mysql...[root@slave-test src]# echo $? 0 [root@slave-test src]#
领取专属 10元无门槛券
手把手带您无忧上云