MySQL的备份有很多种方式,最常用的应该是MySQLdump了,将数据库导出一个 sql文件,还原的时候source db.sql 就欢快的执行了。小
MySQL的备份有很多种方式,最常用的应该是MySQLdump了,将数据库导出一个 sql文件,还原的时候source db.sql 就欢快的执行了。小伙伴愉快的布上一个shell脚本,配上cron,幸福的看着每天备份文件的生成,倍感安全。假如一个MySQL超过了10G呢? 请相信我,导出的时间需要好几个小时,那还原呢,时间会更长。我曾经用sql还原一个6G的数据库,用了3个多小时。
MySQLdump这种逻辑备份的缺点就不多说了,说说xtrabackup,又是PERCONA,就冲这个名号,值得信赖。官方说明:
1、快速可靠
2、备份过程中不中断事务处理
3、节约磁盘空间和网络带宽
4、自动备份验证
5、由于快速还原而带来的高可用行
上面说的,反正我是信了,还是那个6G多的库,全备用了5分钟,还原也只用了5分钟。兄弟们,记住一点,要是真到了用备份来还原数据的时候,你还原几个小时,老板会有想法的!呵呵。
操作系统:CentOS release 6.5
MySQL: 5.6.21
一、安装
yum install
yum install percona-xtrabackup
二、开始使用
xtrabackup包含innobackupex,xtrabackup,xbcrypt,xbstream这几个工具。Innobackupex支持MyISAM,InnoDB。所有,我选择使用innobackupex。
1.创建备份用户,你懂的,最小权限
mysql> create user'bkuser'@'localhost' identified by 'bk2015';
Query OK, 0 rows affected (0.16sec)
mysql> grant reload,locktables,replication client on *.* to 'bkuser'@'localhost';
Query OK, 0 rows affected (0.00sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01sec)
2.使用innobackupex进行数据库全备
innobackupex --user=bkuser--password=bk2015 /mnt/backups
--user 提供连接数据库的用户名
--password 连接数据库的密码
/mnt/backups 备份文件的存储路径
命令执行完成后在/mnt/backups目录下生成了2015-02-03_15-11-51目录,该目录就是我们当前数据库的一个完整备份。该目录是innobackupex自动生成的目录,有一个参数可以控制该选项--no-timestamp,如果加上该参数,将不会自动生成目录,备份创建在提供的路径下。该参数在脚本中使用比较方便。
3.使用完整备份进行数据库还原
还原准备工作
innobackupex --apply-log/mnt/backups/2015-02-03_15-11-51
--apply-log 创建的备份中可能有些未提交的事务,需要回滚或者从日志进行回放
还原
停止mysql服务,
service mysqld stop
备份原有的mysql数据目录
mv /mnt/data/mysql /mnt/data/mysql20150203
执行还原操作
innobackupex --copy-back/mnt/backups/2015-02-03_15-11-51/
改变目录权限,启动服务
chown –R mysql.mysql /mnt/data/mysql
service mysqld start
4.innobackupex增量备份
增量备份需要一次完成备份为基础,在全备的基础上,下次备份仅备份当前时间到上次完备基础上变化的数据。最大的好处是节约磁盘空间。当然,不好的地方是还原,还原的流程将变的复杂
4.1 首先进行全备
innobackupex --user=bkuser --password=bk2015 /mnt/backups
在备份目录2015-02-03_15-11-51中有个xtrabackup-checkpoints,内容如下:
backup_type = full-backuped
from_lsn = 0
to_lsn = 1291135
创建增量备份
innobackupex --incremental /mnt/backups --incremental-basedir=/mnt/backups/2015-02-03_15-11-51--incremental 使用该参数创建增量备份
--incremental-basedir 指定上一次备份的目录,比如这是完整备份后的第一次增备,该目录是完备的目录,如果这是第二次增备,则该目录是第一次增备的目录
检查增备目录的文件中的xtraback_checkpoint文件内容,会发现,lsn发生了变化
backup_type = incrementalfrom_lsn = 1291135to_lsn = 1352113
5.增量备份的还原
5.1 还原准备工作
流程: --apply-log 应用到全备目录,第一次增备,第二增备……第N次增备,全部应用完成后相当于全备+所有增备 的一个新的全备。
innobackupex --apply-log --redo-only BASE-DIR
innobackupex --apply-log --redo-only BASE-DIR --incremental-dir=INCREMENTAL-DIR-1innobackupex --apply-log BASE-DIR --incremental-dir=INCREMENTAL-DIR-2BASE-DIR 全备目录
INCREMENTAL-DIR-1 第一次增备
INCREMENTAL-DIR-2 第二次增备
--redo-only 重要,,每次增备都需要指定该参数,除了最后一次。否则未提交的事务将执行rollback。
以上步骤完成后,再次执行
innobackupex --apply-log BASE-DIR剩下的步骤按照全备的方式还原即可
MySQL管理之使用XtraBackup进行热备
MySQL开源备份工具Xtrabackup备份部署
MySQL Xtrabackup备份和恢复
用XtraBackup实现MySQL的主从复制快速部署【主不锁表】
安装和使用 Percona 推出的 Xtrabackup 备份 MySQL
XtraBackup 的详细介绍:请点这里
XtraBackup 的下载地址:请点这里
本文永久更新链接地址:

The main difference between MySQL and SQLite is the design concept and usage scenarios: 1. MySQL is suitable for large applications and enterprise-level solutions, supporting high performance and high concurrency; 2. SQLite is suitable for mobile applications and desktop software, lightweight and easy to embed.

Indexes in MySQL are an ordered structure of one or more columns in a database table, used to speed up data retrieval. 1) Indexes improve query speed by reducing the amount of scanned data. 2) B-Tree index uses a balanced tree structure, which is suitable for range query and sorting. 3) Use CREATEINDEX statements to create indexes, such as CREATEINDEXidx_customer_idONorders(customer_id). 4) Composite indexes can optimize multi-column queries, such as CREATEINDEXidx_customer_orderONorders(customer_id,order_date). 5) Use EXPLAIN to analyze query plans and avoid

Using transactions in MySQL ensures data consistency. 1) Start the transaction through STARTTRANSACTION, and then execute SQL operations and submit it with COMMIT or ROLLBACK. 2) Use SAVEPOINT to set a save point to allow partial rollback. 3) Performance optimization suggestions include shortening transaction time, avoiding large-scale queries and using isolation levels reasonably.

Scenarios where PostgreSQL is chosen instead of MySQL include: 1) complex queries and advanced SQL functions, 2) strict data integrity and ACID compliance, 3) advanced spatial functions are required, and 4) high performance is required when processing large data sets. PostgreSQL performs well in these aspects and is suitable for projects that require complex data processing and high data integrity.

The security of MySQL database can be achieved through the following measures: 1. User permission management: Strictly control access rights through CREATEUSER and GRANT commands. 2. Encrypted transmission: Configure SSL/TLS to ensure data transmission security. 3. Database backup and recovery: Use mysqldump or mysqlpump to regularly backup data. 4. Advanced security policy: Use a firewall to restrict access and enable audit logging operations. 5. Performance optimization and best practices: Take into account both safety and performance through indexing and query optimization and regular maintenance.

How to effectively monitor MySQL performance? Use tools such as mysqladmin, SHOWGLOBALSTATUS, PerconaMonitoring and Management (PMM), and MySQL EnterpriseMonitor. 1. Use mysqladmin to view the number of connections. 2. Use SHOWGLOBALSTATUS to view the query number. 3.PMM provides detailed performance data and graphical interface. 4.MySQLEnterpriseMonitor provides rich monitoring functions and alarm mechanisms.

The difference between MySQL and SQLServer is: 1) MySQL is open source and suitable for web and embedded systems, 2) SQLServer is a commercial product of Microsoft and is suitable for enterprise-level applications. There are significant differences between the two in storage engine, performance optimization and application scenarios. When choosing, you need to consider project size and future scalability.

In enterprise-level application scenarios that require high availability, advanced security and good integration, SQLServer should be chosen instead of MySQL. 1) SQLServer provides enterprise-level features such as high availability and advanced security. 2) It is closely integrated with Microsoft ecosystems such as VisualStudio and PowerBI. 3) SQLServer performs excellent in performance optimization and supports memory-optimized tables and column storage indexes.


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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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

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),
