MySql Innodb storage engine--backup and optimization

 

Purpose of backup

Do disaster recovery: recover and restore damaged data

Changes in requirements: due to changes in requirements, the data needs to be restored to before the changes

Test: Test if new features are available

 

Backup considerations

How much data loss can be tolerated;

How long does it take to restore data; 

Whether it is necessary to continue to provide services during recovery;

The recovered object is the entire library, multiple tables, or a single library, a single table.

 

type of backup

1. According to whether the database needs to be offline

Cold backup: MySQL service needs to be closed, and read and write requests are not allowed to be performed;

Warm backup: The service is online, but only supports read requests and does not allow write requests;

Hot backup: During the backup, the business is not affected.

Note:

1. This type of backup depends on the needs of the business, not the backup tool

2. MyISAM does not support hot backup, InnoDB supports hot backup, but requires special tools

2. According to the scope of the data set to be backed up

Full backup: full backup, backs up all character sets.

Incremental backup: incremental backup The data that has changed since the last full backup or incremental backup cannot be used alone. With the help of full backup, the frequency of backup depends on the frequency of data update.

Differential backup: Differential backup The data that has changed since the last full backup.

Recommended recovery strategy:

full + incremental + binary log

full + diff + binary log 

 

backed up objects

1. Data;

2. Configuration file;

3. Code: stored procedures, stored functions, triggers

4. OS related configuration files

5. Copy the relevant configuration

6. Binary log

 

 

 

 

mysqldump basic syntax

mysqldump -u username -p dbname table1 table2 ...-> BackupName.sql Use the root user to back up the person table under the test database

mysqldump -u root -p test person > D:\backup.sql

 

mysqlimport

mysqlimport [options] db_name textfile1 [textfile2 ...]
-- Import two files at the same time
mysqlimport --use-threads=2 test /home/mysql/t.txt /home/mysql/s.txt

 

 

select into , load data, source

SELECT ... FROM TABLE_A
INTO OUTFILE "/path/to/file"
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n';

LOAD DATA INFILE "/path/to/file" INTO TABLE table_name;
Note: If the FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' statement is used when exporting, then the same separation restriction statement should be added to the LODA. Also pay attention to encoding issues.
mysql>use dbtest;
mysql>set names utf8;
mysql>source D:/www/sql/back.sql;

 

mysqlbinlog

mysqlbinlog [options] log_file ...
--Import xxx.binlog.000001 to the c drive
mysqlbinlog --start-position=4 --stop-position=106 xxx_binglog.000001 > c:\\test1.txt

 

Hot Standby Tool

ibbackup

XtraBackup

 

other

LVM snapshot backup, backed up by a snapshot of the file system

replication backup

replication+LVM backup

 

Replication replication is a high-availability solution provided by MySql. The principle of replication

1. The main server master short-cut data changes to the binary log binlog

2. The slave server copies the binary log of the master server to its own relay log relay log

3. Redo the log in the relay log from the server and apply the changes to its own database to achieve eventual consistency of the data

It should be noted that because delayed replication cannot achieve real-time synchronization


 

If the DBA performs some accidental deletion operations on the master server, the slave server will also synchronize these operations, so that the wrong operations will also be synchronized, which will not achieve the purpose of backup, so use replication + snapshot to achieve better backup


 

 

 

 

 

 

performance optimization

OLTP online transaction processing is less demanding on CPU but requires more memory

OLAP online analytical processing requires more queries and connections and is CPU-intensive 

 

When the memory exceeds the total size of the data, the performance will increase linearly, but the effect of continuing to increase the memory will not be obvious.

inodb_read related parameters

SHOW GLOBAL STATUS LIKE 'innodb%read%';

innodb_buffer_pool_reads indicates the number of times pages were read from the physical disk

innodb_buffer_pool_read_ahead number of read ahead

innodb_buffer_pool_read_ahead_evicted The number of pre-read pages, but the number of pages that are replaced from the buffer pool without being read, generally used to judge the efficiency of pre-reading

innodb_buffer_pool_read_requests The number of times pages were read from the buffer pool

innodb_data_read The total number of bytes read

innodb_data_reads The number of times that read requests are initiated, and how many pages may be read per read

 

Multiple disks can be formed into RAID to provide performance and high availability, or SSD can be used to provide performance

RAID-0 has the best performance, but the least security


 

RAID-1 has the best security, but the lowest utilization


 

RAID-5 combines the characteristics of RAID-0 and RAID-1, adds parity, and puts the parity data of the disk into other disks, so that even if the damaged disk is damaged, it is not afraid


 

RAID10 and RAID01 combine the features of RAID1 and RAID0

RAID10 has better read speed, RAID01 has better write speed than RAID10, but the security is a little worse, now generally used is

RAID10比较多,此外还有RAID50


 

 

RAID卡 write-through和write-back模式

Write-Through 模式: 

1. DB向Cell发送一个写请求, cellsrv进行验证确认其请求有效; 

2. cellsrv将发送指令将其写入到物理磁盘; 

3. 写完成以后,给DB确认已经写成功; 

4. cellsrv判断次数据是否适合缓存到cache中,如果满足条件则缓存,否则不缓存。

Write-Back 模式: 

1. DB向Cell发送一个写请求, cellsrv进行验证确认其请求有效; 

2. cellsrv将发送指令将其写入到磁盘Cache; 

3. 将此数据的状态置为dirty的状态。(直到下次临界条件将脏数据刷新到磁盘,并判断此数据是否适合缓存,如果不适合,刷新完成以后会丢弃,刷新和缓存过程是异步的,并不在步骤3来完成) 

4. 写完成以后,给DB确认已经写成功;


这两种模式相比,明显write-back效率要高很多,因为每次都是写入到RAID卡的缓存中,再异步刷新到磁盘上,RAID卡也带了备用电池,所以当开启电池后可以安全的使用这种模式,当电池在充电或者没电的时候就会使用write-through模式

 

 

不同的操作系统,文件系统对性能影响并不大

两个基准测试工具

sysbench

mysql-tpcc

 

 

 

 

 

参考

MySQL select into outfile用法

使用mysqlimport 将格式化文件导入mysql表

MySQL 数据备份与还原

[InnoDB系列] -- 实测ibbackup vs mysqldump

使用Xtrabackup来备份你的mysql 

MySQL实验室DMB数据库监控及灾备系统 之 [备份模式的选择]

Cache写策略——write-through与write-back

sysbench安装、使用、结果解读

[Mysql高可用]——双主互备+keepalived

基于keepalived 实现VIP转移,lvs,nginx的高可用

VRRP虚拟路由器冗余协议

针对SSD的MySQL IO优化

mysql优化参数

Innodb存储引擎的编译和调试

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326441157&siteId=291194637