一、背景 线上的一个库一直都是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;
到此工作已经完成:

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1
Powerful PHP integrated development environment

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool