percona-xtrabackup软件包中中包含了两个工具,一个是xtrabackup,另一个是innobackupex,innobackupex由per进行封装,在对innod
目录
1、工具介绍
2、工具安装
3、备份策略及准备测试数据
4、全备份数据
5、增量备份数据
6、灾难恢复
7、总结
1、工具介绍
percona-xtrabackup软件包中中包含了两个工具,一个是xtrabackup,另一个是innobackupex,innobackupex由per进行封装,在对innodb表进行备份时会自动调用xtraback工具,所以对InnoDB表做备份的实际是xtrabackup这个工具,,xtrabackup也只能对innodb表做备份,这是一个专门对innodb开发的热备工具,而对myisam这样的其他引擎的表则由innobackupex来负责备份,若是全备份加增量的方案,那每次增量innobackupex工具对非innodb表都是全备份且会请求读锁。
xtrabackup对innodb表进行备份时不再只是简单复制文件,而是利用在innodb存储引擎层中的LSN(日志序列号)的新旧来识别这一数据页是否需要备份。
xtraback工具对innodb引擎完美支持真正的热备份,备份好的数据中数据文件与事务日志的文件因innodb cache等因素的存在,所以备份好的数据和事务日志中的数据往往是不一致的,所以,在做数据恢复时需要把事务日志中已提交的事务做redo,没有提交的事务做undo操作,这就是在做数据恢复时要做的准备工作,即prepare。
2、工具安装
系统环境:
[root@mariadb ~]# cat /etc/issue
CentOS release 6.4 (Final)
Kernel \r on an \m
[root@mariadb software]# uname -r
2.6.32-358.el6.x86_64
安装依赖包及percona-xtrabackup:
12 [root@mariadb ~]# yum -y install perl perl-devel libaio libaio-devel perl-Time-HiRes perl-DBD-MySQL
[root@mariadb ~]# rpm -ivh percona-xtrabackup-2.1.9-744.rhel6.x86_64.rpm #安装的2.1.9版本
顺便把percona的工具集装上:
12 [root@mariadb ~]# yum -y install perl-IO-Socket-SSL #percona-toolkit依赖包
[root@mariadb ~]# rpm -ivh percona-toolkit-2.2.13-1.noarch.rpm
3、备份策略及准备测试数据
采用先全备份加增量备份的方案。在利用xtrabackup对innodb表做备份工作时,建议mysql启用“innodb_file_per_table=1”变量,这样使每表都有一个自己的表空间,不然很难进行单表备份和还原。还有一点建议,二进制日志文件就不要与数据文件放在同一个目录了,你不想当数据丢失时,二进制日志也一同丢了。
测试数据:
mysql> SELECT VERSION();
+------------+
| VERSION() |
+------------+
| 5.5.36-log |
+------------+
1 row in set (0.00 sec)
mysql> SHOW DATABASES; #创建了一个mydb1数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydb1 |
| mysql |
| performance_schema |
| test |
+--------------------+
mysql> SELECT * FROM mydb1.tb1; #表中只有一条数据
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | tom | 10 |
+----+------+------+
创建备份数据存放目录:
[root@mariadb ~]# mkdir -pv /backup/{fullbackup,incremental}
#fullbackup 存放全备份数据
#incremental 存放增量备份数据
创建复制用户:
mysql> GRANT RELOAD,LOCK TABLES,REPLICATION CLIENT ON *.* TO 'bkuser'@'localhost' IDENTIFIED BY '123456';
mysql> FLUSH PRIVILEGES;
4、全备份数据
[root@mariadb ~]# innobackupex --user=bkuser --password=123456 /backup/fullbackup/
#最后出现“150415 16:30:23 innobackupex: completed OK!”这样的信息表示备份完成
[root@mariadb ~]# ls /backup/fullbackup/2015-04-15_16-30-19/
backup-my.cnf mysql xtrabackup_binary xtrabackup_logfile
ibdata1 performance_schema xtrabackup_binlog_info
mydb1 test xtrabackup_checkpoints
[root@mariadb ~]# cat /backup/fullbackup/2015-04-15_16-30-19/xtrabackup_checkpoints
backup_type = full-backuped
from_lsn = 0
to_lsn = 1644877
last_lsn = 1644877
compact = 0
5、增量备份数据
先做一些数据修改:
mysql> INSERT INTO mydb1.tb1 (name,age) VALUES ('jack',20);
mysql> SELECT * FROM tb1; #增加一条数据
+----+------+------+
| id | name | age |
+----+------+------+
| 1 | tom | 10 |
| 2 | jack | 20 |
+----+------+------+
做第一次增量备份:
[root@mariadb ~]# innobackupex --user=bkuser --password=123456 --incremental /backup/incremental/ --incremental-basedir=/backup/fullbackup/2015-04-15_16-30-19/
[root@mariadb ~]# ls /backup/incremental/2015-04-15_16-42-00/
backup-my.cnf mydb1 test xtrabackup_checkpoints
ibdata1.delta mysql xtrabackup_binary xtrabackup_logfile
ibdata1.meta performance_schema xtrabackup_binlog_info
[root@mariadb ~]# cat /backup/incremental/2015-04-15_16-42-00/xtrabackup_checkpoints
backup_type = incremental
from_lsn = 1644877 #这是全备时的"to_lsn"值
to_lsn = 1645178
last_lsn = 1645178
compact = 0

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters


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

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

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

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools
