Xtrabackup备份mysql实战(做从库全过程)
一、背景 线上的一个库一直都是RD他们自己维护的,由于业务的增长,现在数据已经500G+了,急需做一个从库,登陆机器一瞅,坑爹啊,还是mysql5.6(我们维护的都是5.5),mysql5.6还没有搞过呢,还有就是他这安装的都不是按我们运维的标准安装的,我的第一反应
一、背景
线上的一个库一直都是RD他们自己维护的,由于业务的增长,现在数据已经500G+了,急需做一个从库,登陆机器一瞅,坑爹啊,还是mysql5.6(我们维护的都是5.5),mysql5.6还没有搞过呢,还有就是他这安装的都不是按我们运维的标准安装的,我的第一反应就是这活没法干,这个库又不容许停库太长时间,于是就度娘、QQ群各种请教,最终确定用Xtrabackup试一把,一直在听大家说Xtrabackup这好那好的,却从来没有玩过,我觉得数据备份(用于做从库)还是冷备最好,速度快,还最能保证数据的一致性,但是今天这种情形貌似行不通了,Xtrabackup搞起!!!
二、Xtrabackup相关资料学习
Xtrabackup的有点:
1、备份完成快速、可靠 2、备份期间不间断的事务处理 3、节省磁盘空间和网络带宽 4、自动备份验证 5、提高正常运行时间由于更快的恢复时间
我个人觉的比较好的就是备份不需要锁表(innodb),备份MyISAM的表还是会锁的,还支持增量备份,总之这工具值得赞。
参考文档:
http://www.percona.com/doc/percona-xtrabackup/2.1/
http://www.baidu-ops.com/2013/05/26/xtrabackup/
三、实施
1、环境:
172.28.29.152 主库 172.28.26.138 从库(待做)
2、主库上安装Xtrabackup
yum install perl-Time-HiRes* yum install perl-DBD-MySQL -y wget http://www.percona.com/redir/downloads/XtraBackup/LATEST/RPM/rhel6/x86_64/percona-xtrabackup-2.1.9-744.rhel6.x86_64.rpm rpm -ivh percona-xtrabackup-2.1.9-744.rhel6.x86_64.rpm
3、备份主库
innobackupex --defaults-file=/usr/local/mysql/my.cnf --user root --socket=/data/log/mysql.sock --password 123456 /data/xtrabackup/ & ##备份 ps:备份完成了,会在/data/xtrabackup/目录下生成一个时间点目录,你也可以加一个--no-timestamp参数不生产这个目录,直接备份到 /data/xtrabackup/下 innobackupex --defaults-file=/usr/local/mysql/my.cnf --user root --socket=/data/log/mysql.sock --password 123456 --apply-log /data/xtrabackup/2014-06-04_10-20-55/ & ##preparing,undo撤销未提交的事务,重放redo log
ps:1、ll /data/xtrabackup/2014-06-04_10-20-55/查看,你发现xtrabackup会把你数据库datadir下的所有数据文件都复制过来还新增了5个xtrabackup_开头的文件,我们关心的是xtrabackup_binlog_info这个文件,因为这个文件里面记录了你做从库需要change到主库的binlog的位置和pos点
2、如果只想备份一个库,加“--include=navy”指定库名即可, “--databases=navy”不好使,被坑过。
4、从库安装mysql5.6
主库的mysql是RD编译安装的,路径/usr/local/mysql/,那么从库你还苦逼的再编译一次吗?不用了,直接把主库的安装目录scp过来就可以用,my.cnf也scp过来,日志和datadir目录的宿主一定要是mysql哦,之后就可以初始化启动库了。
scp -r /usr/local/mysql/ 172.28.26.138:/usr/local/ chown mysql:mysql /data/log/ -R ##日志和pid存放目录 chown mysql:mysql /data/mysql/ -R ##datadir /usr/local/mysql/my.cnf 中添加 server-id = 2 /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/ 初始化数据库 /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf --user=mysql & 启动数据库 /usr/local/mysql/bin/mysqladmin --sock=/data/log/mysql.sock -p123456 shutdown 停库,把datadir目录清空,执行下面步骤
PS:主库竟然没有设置server-id,这不是坑爹嘛,别急,这个参数是动态的,可以在线调整,set global server_id=1;就ok了
5、从库服务器把主库备份文件拉到data_dir下
rsync -av 172.28.29.152::xtrabackup/2014-06-04_10-20-55/ /data/mysql/ &
6、启动库,搭建主从,
/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf --user=mysql & cat /data/mysql/xtrabackup_binlog_info mysql-bin.008370 147669327 change master to master_host="172.28.29.152", master_port=3306, master_user='slave', master_password='123456', master_log_file='mysql-bin.008370', master_log_pos=147669327;
到此工作已经完成:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Effective monitoring of Redis databases is critical to maintaining optimal performance, identifying potential bottlenecks, and ensuring overall system reliability. Redis Exporter Service is a powerful utility designed to monitor Redis databases using Prometheus. This tutorial will guide you through the complete setup and configuration of Redis Exporter Service, ensuring you seamlessly build monitoring solutions. By studying this tutorial, you will achieve fully operational monitoring settings
