时间:2021-07-01 10:21:17 帮助过:12人阅读
mysql的配置文件为/etc/my.cnf
配置文件查找次序:若在多个配置文件中均有设定,则最后找到的最终生效
/etc/my.cnf --> /etc/mysql/my.cnf --> --default-extra-file=/PATH/TO/CONF_FILE --> ~/.my.cnf
mysql常用配置文件参数:
参数 | 说明 |
---|---|
port = 3306 | 设置监听端口 |
socket = /tmp/mysql.sock | 指定套接字文件位置 |
basedir = /usr/local/mysql | 指定MySQL的安装路径 |
datadir = /data/mysql | 指定MySQL的数据存放路径 |
pid-file = /data/mysql/mysql.pid | 指定进程ID文件存放路径 |
user = mysql | 指定MySQL以什么用户的身份提供服务 |
skip-name-resolve | 禁止MySQL对外部连接进行DNS解析 使用这一选项可以消除MySQL进行DNS解析的时间。 若开启该选项,则所有远程主机连接授权都要使用IP地址方式否则MySQL将无法正常处理连接请求 |
数据库备份方案:
备份方案 | 特点 |
---|---|
全量备份 | 全量备份就是指对某一个时间点上的所有数据或应用进行的一个完全拷贝。 数据恢复快。 备份时间长. |
增量备份 | 增量备份是指在一次全备份或上一次增量备份后,以后每次的备份只需备份 与前一次相比增加和者被修改的文件。这就意味着,第一次增量备份的对象 是进行全备后所产生的增加和修改的文件;第二次增量备份的对象是进行第一次增量 备份后所产生的增加和修改的文件,如此类推。 没有重复的备份数据 备份时间短 恢复数据时必须按一定的顺序进行 |
差异备份 | 备份上一次的完全备份后发生变化的所有文件。 差异备份是指在一次全备份后到进行差异备份的这段时间 对那些增加或者修改文件的备份。在进行恢复时,我们只需对第一次全量备份和最后一次差异备份进行恢复。 |
//语法:
mysqldump [OPTIONS] database [tables ...]
mysqldump [OPTIONS] --all-databases [OPTIONS]
mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
//常用的OPTIONS:
-uUSERNAME //指定数据库用户名
-hHOST //指定服务器主机,请使用ip地址
-pPASSWORD //指定数据库用户的密码
-P# //指定数据库监听的端口,这里的#需用实际的端口号代替,如-P3307
//备份整个数据库(全备)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| liuzhenchao |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> use liuzhenchao;
Database changed
mysql> show tables;
+-----------------------+
| Tables_in_liuzhenchao |
+-----------------------+
| class |
| student |
+-----------------------+
2 rows in set (0.00 sec)
[root@20liuzhenchao ~]# ls
anaconda-ks.cfg
[root@20liuzhenchao ~]# mysqldump -uroot -p -h127.0.0.1 --all-databases > all-201904291610.sql
Enter password:
[root@20liuzhenchao ~]# ls
all-201904291610.sql anaconda-ks.cfg
//备份liuzhenchao库的student表和class表
[root@20liuzhenchao ~]# mysqldump -uroot -p -h127.0.0.1 liuzhenchao student class > table-201904291616.sql
Enter password:
[root@20liuzhenchao ~]# ls
all-201904291610.sql anaconda-ks.cfg table-201904291616.sql
//备份liuzhenchao库
[root@20liuzhenchao ~]# mysqldump -uroot -p -h127.0.0.1 --databases liuzhenchao > zc-201904291618.sql
Enter password:
[root@20liuzhenchao ~]# ls
all-201904291610.sql anaconda-ks.cfg table-201904291616.sql zc-201904291618.sql
//模拟误删liuzhenchao数据库
mysql> drop database liuzhenchao;
Query OK, 2 rows affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
//恢复liuzhenchao数据库
[root@20liuzhenchao ~]# ls
all-201904291610.sql anaconda-ks.cfg table-201904291616.sql zc-201904291618.sql
[root@20liuzhenchao ~]# mysql -uroot -p -h127.0.0.1 < all-201904291610.sql
Enter password:
[root@20liuzhenchao ~]# mysql -uroot -p -h127.0.0.1 -e ‘show databases;‘
Enter password:
+--------------------+
| Database |
+--------------------+
| information_schema |
| liuzhenchao |
| mysql |
| performance_schema |
| sys |
+--------------------+
//恢复liuzhenchao数据库的student表和class表
mysql> use liuzhenchao;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> source table-201904291616.sql;
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
......
......
Query OK, 0 rows affected (0.00 sec)
mysql> show tables;
+-----------------------+
| Tables_in_liuzhenchao |
+-----------------------+
| class |
| student |
+-----------------------+
2 rows in set (0.00 sec)
开启MySQL服务器的二进制日志功能 [root@20liuzhenchao ~]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
user = mysql
pid-file = /tmp/mysql.pid
skip-name-resolve
server-id=10 //设置服务器标识符
log-bin=mysql_bin //开启二进制日志功能
[root@20liuzhenchao ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
对数据库进行完全备份
//备份整个数据库(全备)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| liuzhenchao |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> use liuzhenchao;
Database changed
mysql> show tables;
+-----------------------+
| Tables_in_liuzhenchao |
+-----------------------+
| class |
| student |
+-----------------------+
2 rows in set (0.00 sec)
[root@20liuzhenchao ~]# ls
anaconda-ks.cfg
[root@20liuzhenchao ~]# mysqldump -uroot -p -h127.0.0.1 --all-databases > all-201904291610.sql
Enter password:
[root@20liuzhenchao ~]# ls
all-201904291610.sql anaconda-ks.cfg
//增加新内容
[root@20liuzhenchao ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| liuzhenchao |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.05 sec)
mysql> use liuzhenchao;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+-----------------------+
| Tables_in_liuzhenchao |
+-----------------------+
| class |
| student |
+-----------------------+
2 rows in set (0.00 sec)
mysql> select * from class;
+----+--------+
| id | name |
+----+--------+
| 1 | grade1 |
| 2 | grade2 |
+----+--------+
2 rows in set (0.01 sec)
mysql> insert class(id,name) values(3,‘grade3‘),(4,‘grade4‘);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from class;
+----+--------+
| id | name |
+----+--------+
| 1 | grade1 |
| 2 | grade2 |
| 3 | grade3 |
| 4 | grade4 |
+----+--------+
4 rows in set (0.00 sec)
模拟误删数据
[root@20liuzhenchao ~]# mysql -uroot -p‘liu123!@#‘ -e ‘drop database liuzhenchao;‘
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@20liuzhenchao ~]# mysql -uroot -p‘liu123!@#‘ -e ‘show databases;‘
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
//由上可以看到liuzhenchao这个数据库已被删除
刷新创建新的二进制日志
[root@20liuzhenchao ~]# ll /opt/data/
总用量 122964
-rw-r-----. 1 mysql mysql 31892 4月 30 17:34 20liuzhenchao.err
-rw-r-----. 1 mysql mysql 56 4月 29 23:00 auto.cnf
-rw-r-----. 1 mysql mysql 453 4月 30 17:34 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 4月 30 17:49 ibdata1
-rw-r-----. 1 mysql mysql 50331648 4月 30 17:49 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 4月 29 23:00 ib_logfile1
-rw-r-----. 1 mysql mysql 12582912 4月 30 17:34 ibtmp1
drwxr-x---. 2 mysql mysql 4096 4月 30 00:24 mysql
-rw-r-----. 1 mysql mysql 177 4月 30 17:34 mysql_bin.000001
-rw-r-----. 1 mysql mysql 624 4月 30 17:49 mysql_bin.000002
-rw-r-----. 1 mysql mysql 38 4月 30 17:34 mysql_bin.index
-rw-r-----. 1 mysql mysql 5 4月 30 17:34 mysql.pid
drwxr-x---. 2 mysql mysql 8192 4月 29 23:00 performance_schema
drwxr-x---. 2 mysql mysql 8192 4月 29 23:00 sys
//刷新创建新的二进制日志
[root@20liuzhenchao ~]# mysqladmin -uroot -p‘liu123!@#‘ flush-logs
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[root@20liuzhenchao ~]# ll /opt/data
总用量 122968
-rw-r-----. 1 mysql mysql 31892 4月 30 17:34 20liuzhenchao.err
-rw-r-----. 1 mysql mysql 56 4月 29 23:00 auto.cnf
-rw-r-----. 1 mysql mysql 453 4月 30 17:34 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 4月 30 17:49 ibdata1
-rw-r-----. 1 mysql mysql 50331648 4月 30 17:49 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 4月 29 23:00 ib_logfile1
-rw-r-----. 1 mysql mysql 12582912 4月 30 17:34 ibtmp1
drwxr-x---. 2 mysql mysql 4096 4月 30 00:24 mysql
-rw-r-----. 1 mysql mysql 177 4月 30 17:34 mysql_bin.000001
-rw-r-----. 1 mysql mysql 671 4月 30 17:51 mysql_bin.000002
-rw-r-----. 1 mysql mysql 154 4月 30 17:51 mysql_bin.000003
-rw-r-----. 1 mysql mysql 57 4月 30 17:51 mysql_bin.index
-rw-r-----. 1 mysql mysql 5 4月 30 17:34 mysql.pid
drwxr-x---. 2 mysql mysql 8192 4月 29 23:00 performance_schema
drwxr-x---. 2 mysql mysql 8192 4月 29 23:00 sys
恢复完全备份
[root@20liuzhenchao ~]# mysql -uroot -p‘liu123!@#‘ < all-201904291610.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@20liuzhenchao ~]# mysql -uroot -p‘liu123!@#‘ -e ‘show databases;‘
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| liuzhenchao |
| mysql |
| performance_schema |
| sys |
+--------------------+
[root@localhost ~]# mysql -uroot -pwangqing123! -e ‘show tables from wangqing;‘
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Tables_in_wangqing |
+--------------------+
| runtime |
| student |
+--------------------+
[root@20liuzhenchao ~]# mysql -uroot -p‘liu123!@#‘ -e ‘select * from liuzhenchao.class;‘
mysql: [Warning] Using a password on the command line interface can be insecure.
+----+--------+
| id | name |
+----+--------+
| 1 | grade1 |
| 2 | grade2 |
+----+--------+
恢复差异备份
//检查误删数据库的位置在什么地方
[root@20liuzhenchao ~]# mysql -uroot -p‘liu123!@#‘
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> show binlog events in ‘mysql_bin.000002‘;
+------------------+-----+----------------+-----------+-------------+---------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+------------------+-----+----------------+-----------+-------------+---------------------------------------+
| mysql_bin.000002 | 4 | Format_desc | 10 | 123 | Server ver: 5.7.22-log, Binlog ver: 4 |
| mysql_bin.000002 | 123 | Previous_gtids | 10 | 154 | |
| mysql_bin.000002 | 154 | Anonymous_Gtid | 10 | 219 | SET @@SESSION.GTID_NEXT= ‘ANONYMOUS‘ |
| mysql_bin.000002 | 219 | Query | 10 | 298 | BEGIN |
| mysql_bin.000002 | 298 | Table_map | 10 | 356 | table_id: 108 (liuzhenchao.class) |
| mysql_bin.000002 | 356 | Write_rows | 10 | 415 | table_id: 108 flags: STMT_END_F |
| mysql_bin.000002 | 415 | Xid | 10 | 446 | COMMIT /* xid=14 */ |
| mysql_bin.000002 | 446 | Anonymous_Gtid | 10 | 511 | SET @@SESSION.GTID_NEXT= ‘ANONYMOUS‘ |
| mysql_bin.000002 | 511 | Query | 10 | 624 | drop database liuzhenchao |
| mysql_bin.000002 | 624 | Rotate | 10 | 671 | mysql_bin.000003;pos=4 |
+------------------+-----+----------------+-----------+-------------+---------------------------------------+
10 rows in set (0.01 sec)
//使用mysqlbinlog恢复差异备份
[root@20liuzhenchao ~]# mysqlbinlog --stop-position=511 /opt/data/mysql_bin.000002 |mysql -uroot -p‘liu123!@#‘
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@20liuzhenchao ~]# mysql -uroot -p‘liu123!@#‘ -e ‘select * from liuzhenchao.class‘
mysql: [Warning] Using a password on the command line interface can be insecure.
+----+--------+
| id | name |
+----+--------+
| 1 | grade1 |
| 2 | grade2 |
| 3 | grade3 |
| 4 | grade4 |
+----+--------+
Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个很好的替代品。它能对InnoDB和XtraDB存储引擎的数据库非阻塞地备份(对于MyISAM的备份同样需要加表锁)。XtraBackup支持所有的Percona Server、MySQL、MariaDB和Drizzle。
Xtrabackup是由percona开源的免费数据库热备份软件,它能对InnoDB数据库和XtraDB存储引擎的数据库非阻塞地备份(对于MyISAM的备份同样需要加表锁);mysqldump备份方式是采用的逻辑备份,其最大的缺陷是备份和恢复速度较慢,如果数据库大于50G,mysqldump备份就不太适合。
备份开始时首先会开启一个后台检测进程,实时检测mysq redo的变化,一旦发现有新的日志写入,立刻将日志记入后台日志文件xtrabackup_log中,之后复制innodb的数据文件一系统表空间文件ibdatax,复制结束后,将执行flush tables with readlock,然后复制.frm MYI MYD等文件,最后执行unlock tables,最终停止xtrabackup_log
xtrabackup增量备份的原理是:
增量备份优点:
[root@20liuzhenchao ~]# yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
percona-release-0.1-4.noarch.rpm | 6.4 kB 00:00:00
正在检查 /var/tmp/yum-root-N7jrMj/percona-release-0.1-4.noarch.rpm: percona-release-0.1-4.noarch
/var/tmp/yum-root-N7jrMj/percona-release-0.1-4.noarch.rpm 将作为 percona-release-0.1-3.noarch 的更新
正在解决依赖关系
--> 正在检查事务
---> 软件包 percona-release.noarch.0.0.1-3 将被 升级
---> 软件包 percona-release.noarch.0.0.1-4 将被 更新
更新完毕:
percona-release.noarch 0:0.1-4
完毕!
[root@20liuzhenchao ~]# yum list | grep percona
percona-release.noarch 0.1-4 installed
Percona-Server-55-debuginfo.x86_64 5.5.62-rel38.14.el7 percona-release-x86_64
Percona-Server-56-debuginfo.x86_64 5.6.43-rel84.3.el7 percona-release-x86_64
Percona-Server-57-debuginfo.x86_64 5.7.25-28.1.el7 percona-release-x86_64
Percona-Server-80-info.x86_64 8.0-1.el7 percona-release-x86_64
//安装percona
[root@20liuzhenchao ~]# yum -y install percona-xtrabackup-24
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
正在解决依赖关系
--> 正在检查事务
已安装:
percona-xtrabackup-24.x86_64 0:2.4.13-1.el7
作为依赖被安装:
libev.x86_64 0:4.15-7.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7
perl-DBD-MySQL.x86_64 0:4.023-6.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7
perl-Digest.noarch 0:1.17-245.el7 perl-Digest-MD5.x86_64 0:2.52-3.el7 perl-IO-Compress.noarch 0:2.061-2.el7
perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7 rsync.x86_64 0:3.1.2-4.el7
完毕!
[root@20liuzhenchao ~]# which xtrabackup
/usr/bin/xtrabackup
[root@20liuzhenchao ~]# innobackupex -v
xtrabackup: recognized server arguments: --datadir=/opt/data --server-id=10 --log_bin=mysql_bin
innobackupex version 2.4.13 Linux (x86_64) (revision id: 3e7ca7c)
//已安装完成
mysql> create database test;
Query OK, 1 row affected (0.01 sec)
mysql> use test;
Database changed
mysql> create table T1(name varchar(10) not null,sex varchar(10) not null);
Query OK, 0 rows affected (0.01 sec)
mysql> insert into T1 values(‘zhang‘,‘man‘),(‘zhan‘,‘man‘),(‘sun‘,‘woman‘);
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from T1;
+-------+-------+
| name | sex |
+-------+-------+
| zhang | man |
| zhan | man |
| sun | woman |
+-------+-------+
3 rows in set (0.00 sec)
[root@20liuzhenchao ~]# innobackupex --defaults-file=/etc/my.cnf --user=root --host=127.0.0.1 --password=‘liu123!@#‘ --port=3306 --backup /root
xtrabackup: recognized server arguments: --datadir=/opt/data --server-id=10 --log_bin=mysql_bin
xtrabackup: recognized client arguments: --datadir=/opt/data --server-id=10 --log_bin=mysql_bin --backup=1
190501 04:53:58 innobackupex: Starting the backup operation
IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackupex
prints "completed OK!".
190501 04:53:58 version_check Connecting to MySQL server with DSN ‘dbi:mysql:;mysql_read_default_group=xtrabackup;host=127.0.0.1;port=3306‘ as ‘root‘ (using password: YES).
190501 04:54:00 version_check Connected to MySQL server
190501 04:54:00 version_check Executing a version check against the server...
190501 04:54:00 version_check Done.
190501 04:54:00 Connecting to MySQL server host: 127.0.0.1, user: root, password: set, port: 3306, socket: not set
Using server version 5.7.22-log
innobackupex version 2.4.13 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 3e7ca7c)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /opt/data
xtrabackup: open files limit requested 0, set to 1024
xtrabackup: using the following InnoDB configuration:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:12M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 50331648
InnoDB: Number of pools: 1
......
......
190501 04:54:04 [00] Writing /root/2019-05-01_04-53-58/xtrabackup_info
190501 04:54:04 [00] ...done
xtrabackup: Transaction log of lsn (5374234) to (5374243) was copied.
190501 04:54:04 completed OK!
//这里面就是相关的备份文件,同样也可以看到我们创建的库的名称
[root@20liuzhenchao ~]# ll ./2019-05-01_04-53-58/
总用量 12340
-rw-r-----. 1 root root 488 5月 1 04:54 backup-my.cnf
-rw-r-----. 1 root root 705 5月 1 04:54 ib_buffer_pool
-rw-r-----. 1 root root 12582912 5月 1 04:54 ibdata1
drwxr-x---. 2 root root 92 5月 1 04:54 liuzhenchao
drwxr-x---. 2 root root 4096 5月 1 04:54 mysql
drwxr-x---. 2 root root 8192 5月 1 04:54 performance_schema
drwxr-x---. 2 root root 8192 5月 1 04:54 sys
drwxr-x---. 2 root root 48 5月 1 04:54 test
-rw-r-----. 1 root root 21 5月 1 04:54 xtrabackup_binlog_info
-rw-r-----. 1 root root 113 5月 1 04:54 xtrabackup_checkpoints
-rw-r-----. 1 root root 529 5月 1 04:54 xtrabackup_info
-rw-r-----. 1 root root 2560 5月 1 04:54 xtrabackup_logfile
//使用此参数使用相关数据性文件保持一致性状态
[root@20liuzhenchao ~]# innobackupex --apply-log /root/2019-05-01_04-53-58/
xtrabackup: recognized server arguments: --innodb_checksum_algorithm=crc32 --innodb_log_checksum_algorithm=strict_crc32 --innodb_data_file_path=ibdata1:12M:autoextend --innodb_log_files_in_group=2 --innodb_log_file_size=50331648 --innodb_fast_checksum=0 --innodb_page_size=16384 --innodb_log_block_size=512 --innodb_undo_directory=./ --innodb_undo_tablespaces=0 --server-id=10 --redo-log-version=1
xtrabackup: recognized client arguments: --innodb_checksum_algorithm=crc32 --innodb_log_checksum_algorithm=strict_crc32 --innodb_data_file_path=ibdata1:12M:autoextend --innodb_log_files_in_group=2 --innodb_log_file_size=50331648 --innodb_fast_checksum=0 --innodb_page_size=16384 --innodb_log_block_size=512 --innodb_undo_directory=./ --innodb_undo_tablespaces=0 --server-id=10 --redo-log-version=1
190501 04:59:57 innobackupex: Starting the apply-log operation
IMPORTANT: Please check that the apply-log run completes successfully.
At the end of a successful apply-log run innobackupex
prints "completed OK!".
innobackupex version 2.4.13 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 3e7ca7c)
xtrabackup: cd to /root/2019-05-01_04-53-58/
xtrabackup: This target seems to be not prepared yet.
//模拟误删表
mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> drop table T1;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from T1;
ERROR 1146 (42S02): Table ‘test.T1‘ doesn‘t exist
恢复数据之前需要保证数据目录是空的状态
[root@20liuzhenchao data]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=‘liu123!@#‘ --port=3306 --host=127.0.0.1 --copy-back /root/2019-05-01_04-53-58/
xtrabackup: recognized server arguments: --datadir=/opt/data --server-id=10 --log_bin=mysql_bin
xtrabackup: recognized client arguments: --datadir=/opt/data --server-id=10 --log_bin=mysql_bin
190501 05:08:24 innobackupex: Starting the copy-back operation
IMPORTANT: Please check that the copy-back run completes successfully.
At the end of a successful copy-back run innobackupex
prints "completed OK!".
innobackupex version 2.4.13 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 3e7ca7c)
190501 05:08:24 [01] Copying ib_logfile0 to /opt/data/ib_logfile0
190501 05:08:24 [01] ...done
190501 05:08:24 [01] Copying ib_logfile1 to /opt/data/ib_logfile1
190501 05:08:24 [01] ...done
.....
.....
190501 05:08:24 [01] ...done
190501 05:08:24 [01] Copying ./ibtmp1 to /opt/data/ibtmp1
190501 05:08:24 [01] ...done
190501 05:08:25 completed OK!
//重启服务
[root@20liuzhenchao ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
//查看数据是否恢复
[root@20liuzhenchao ~]# mysql -uroot -p‘liu123!@#‘ -e ‘select * from test.T1;‘
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------+-------+
| name | sex |
+-------+-------+
| zhang | man |
| zhan | man |
| sun | woman |
+-------+-------+
mysql进阶
标签:重复 cto 数据 锁表 增量 进程id pex 授权 release