基于Xtrabackup恢复单个innodb表
[root@zlm1 :: ~]
#yum install mysql-utilities Installed:
mysql-utilities.noarch :1.3.-.el7 Dependency Installed:
mysql-connector-python.noarch :1.1.-.el7 Complete!
[root@zlm1 :: ~]
#innobackupex --defaults-file=/data/mysql/mysql3306/my3306.cnf --host=localhost --user=root --password=Passw0rd --sock=/tmp/mysql3306.sock /data/backup
:: 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!". //Omitts the intermedia output. :: Finished backing up non-InnoDB tables and files
:: [] Writing xtrabackup_binlog_info
:: [] ...done
:: Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
xtrabackup: The latest check point (for incremental): ''
xtrabackup: Stopping log copying thread.
. :: >> log scanned up to () :: Executing UNLOCK TABLES
:: All tables unlocked
:: [] Copying ib_buffer_pool to /data/backup/--06_10--/ib_buffer_pool
:: [] ...done
:: Backup created in directory '/data/backup/2018-07-06_10-09-22'
MySQL binlog position: filename 'mysql-bin.000071', position '', GTID of the last change '2a4b3562-2ab6-11e8-be7a-080027de0e0e:1-12715494'
:: [] Writing backup-my.cnf
:: [] ...done
:: [] Writing xtrabackup_info
:: [] ...done
xtrabackup: Transaction log of lsn () to () was copied.
:: completed OK! [root@zlm1 :: ~]
#cd /data/backup [root@zlm1 :: /data/backup]
#ls -l
total
drwxr-x--- root root Jul : --06_10-- [root@zlm1 :: /data/backup]
#cd --06_10--/ [root@zlm1 :: /data/backup/--06_10--]
#ls -l
total
drwxr-x--- root root Jul : aaron8219
-rw-r----- root root Jul : backup-my.cnf
drwxr-x--- root root Jul : -help
-rw-r----- root root Jul : ib_buffer_pool
-rw-r----- root root Jul : ibdata1
drwxr-x--- root root Jul : mysql
drwxr-x--- root root Jul : performance_schema
drwxr-x--- root root Jul : sys
drwxr-x--- root root Jul : sysbench
-rw-r----- root root Jul : xtrabackup_binlog_info
-rw-r----- root root Jul : xtrabackup_checkpoints
-rw-r----- root root Jul : xtrabackup_info
-rw-r----- root root Jul : xtrabackup_logfile
drwxr-x--- root root Jul : zlm
[root@zlm1 :: /data/backup/--06_10--]
#innobackupex --defaults-file=/data/mysql/mysql3306/my3306.cnf --host=localhost --user=root --password=Passw0rd --sock=/tmp/mysql3306.sock --apply-log /data/backup/--06_10--/
:: 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!". //Omitts the intermedia output. InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: xtrabackup: Last MySQL binlog file position , file name mysql-bin.
InnoDB: Removed temporary tablespace data file: "ibtmp1"
InnoDB: Creating shared tablespace for temporary tables
InnoDB: Setting file './ibtmp1' size to MB. Physically writing the file full; Please wait ...
InnoDB: File './ibtmp1' size is now MB.
InnoDB: redo rollback segment(s) found. redo rollback segment(s) are active.
InnoDB: non-redo rollback segment(s) are active.
InnoDB: Waiting for purge to start
InnoDB: 5.7. started; log sequence number
xtrabackup: starting shutdown with innodb_fast_shutdown =
InnoDB: page_cleaner: 1000ms intended loop took 10865ms. The settings might not be optimal. (flushed= and evicted=, during the time.)
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number
:: completed OK!
root@localhost:mysql3306.sock [(none)]>show tables from zlm;
+----------------+
| Tables_in_zlm |
+----------------+
| customer |
| goods |
| semi_sync_test |
| test_flashbk |
| test_myisam |
+----------------+
rows in set (0.00 sec) root@localhost:mysql3306.sock [(none)]>show tables from sysbench;
+--------------------+
| Tables_in_sysbench |
+--------------------+
| sbtest1 |
| sbtest10 |
| sbtest2 |
| sbtest3 |
| sbtest4 |
| sbtest5 |
| sbtest6 |
| sbtest7 |
| sbtest8 |
| sbtest9 |
+--------------------+
rows in set (0.00 sec) root@localhost:mysql3306.sock [(none)]>drop table zlm.test_flashbk,sysbench.sbtest1;
Query OK, rows affected (0.11 sec)
[root@zlm1 :: /data/backup/--06_10--]
#mysqlfrm --basedir=/usr/local/mysql --port= --diagnostic /data/backup/--06_10--/sysbench/sbtest1.frm /data/backup/--06_10--/zlm/zlm:test_flashbk.frmsbtest1.frm /data/backup/--06_10--/zlm/zlm:tes
# WARNING The --port option is not used in the --diagnostic mode.
# WARNING: Cannot generate character set or collation names without the --server option.
# CAUTION: The diagnostic mode is a best-effort parse of the .frm file. As such, it may not identify all of the components of the table correctly. This is especially true for damaged files. It will also not read the default values for the columns and the resulting statement may not be syntactically correct.
# Reading .frm file for /data/backup/--06_10--/sysbench/sbtest1.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement: CREATE TABLE `sysbench`.`sbtest1` (
`id` int() NOT NULL AUTO_INCREMENT,
`k` int() NOT NULL,
`c` char() NOT NULL,
`pad` char() NOT NULL,
PRIMARY KEY `PRIMARY` (`id`),
KEY `k_1` (`k`)
) ENGINE=InnoDB; # Reading .frm file for /data/backup/--06_10--/zlm/test_flashbk.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement: CREATE TABLE `zlm`.`test_flashbk` (
`id` bigint() NOT NULL AUTO_INCREMENT,
`name` varchar() NOT NULL,
PRIMARY KEY `PRIMARY` (`id`)
) ENGINE=InnoDB; #...done. //If you want to get the information of character set,"--server" is indispensable.
//you can either use <dbname>:<tablename>.frm or just <tablename>.frm.
//"--port" can be omitted.
root@localhost:mysql3306.sock [(none)]>CREATE TABLE `sysbench`.`sbtest1` (
-> `id` int() NOT NULL AUTO_INCREMENT,
-> `k` int() NOT NULL,
-> `c` char() NOT NULL,
-> `pad` char() NOT NULL,
-> PRIMARY KEY `PRIMARY` (`id`),
-> KEY `k_1` (`k`)
-> ) ENGINE=InnoDB;
ERROR (): Column length too big for column 'c' (max = ); use BLOB or TEXT instead
root@localhost:mysql3306.sock [(none)]>CREATE TABLE `zlm`.`test_flashbk` (
-> `id` bigint() NOT NULL AUTO_INCREMENT,
-> `name` varchar() NOT NULL,
-> PRIMARY KEY `PRIMARY` (`id`)
-> ) ENGINE=InnoDB;
Query OK, rows affected (0.02 sec) //We get an error when creating table sysbench.sbtest1 beause of the overload value of char.
root@localhost:mysql3306.sock [(none)]>show create table sysbench.sbtest2\G
*************************** . row ***************************
Table: sbtest2
Create Table: CREATE TABLE `sbtest2` (
`id` int() NOT NULL AUTO_INCREMENT,
`k` int() NOT NULL DEFAULT '',
`c` char() NOT NULL DEFAULT '', //In the counterpart table,the value is 120.
`pad` char() NOT NULL DEFAULT '', //In the counterpart table,the value is 60.
PRIMARY KEY (`id`),
KEY `k_2` (`k`)
) ENGINE=InnoDB AUTO_INCREMENT= DEFAULT CHARSET=utf8
row in set (0.00 sec)
when creating table sysbench.sbtest1 beause of the overload value of char. Check the structure of sbtest2 table in sysbench.
root@localhost:mysql3306.sock [(none)]>show create table sysbench.sbtest2\G
*************************** . row ***************************
Table: sbtest2
Create Table: CREATE TABLE `sbtest2` (
`id` int() NOT NULL AUTO_INCREMENT,
`k` int() NO
root@localhost:mysql3306.sock [(none)]>lock tables sysbench.sbtest1 write;
Query OK, rows affected (0.00 sec) root@localhost:mysql3306.sock [(none)]>lock tables zlm.test_flashbk write;
Query OK, rows affected (0.00 sec) root@localhost:mysql3306.sock [(none)]>alter table sysbench.sbtest1 discard tablespace;
ERROR (HY000): Table 'sbtest1' was not locked with LOCK TABLES //when locks another table,the lock on previous table will be released.
root@localhost:mysql3306.sock [(none)]>lock tables sysbench.sbtest1 write; //This time,lock one and discard one in order.
Query OK, rows affected (0.00 sec) root@localhost:mysql3306.sock [(none)]>alter table sysbench.sbtest1 discard tablespace;
Query OK, rows affected (0.00 sec) root@localhost:mysql3306.sock [(none)]>lock tables zlm.test_flashbk write;
Query OK, rows affected (0.00 sec) root@localhost:mysql3306.sock [(none)]>alter table zlm.test_flashbk discard tablespace;
Query OK, rows affected (0.00 sec)
[root@zlm1 :: /data/backup/--06_10--]
#cp sysbench/sbtest1.ibd /data/mysql/mysql3306/data/sysbench [root@zlm1 :: /data/backup/--06_10--]
#cp zlm/test_flashbk.ibd /data/mysql/mysql3306/data/zlm [root@zlm1 :: /data/backup/--06_10--]
#chown -R mysql.mysql /data/mysql/mysql3306/data [root@zlm1 :: /data/backup/--06_10--]
#ls -l /data/mysql/mysql3306/data/sysbench | grep sbtest1.ibd
-rw-r----- mysql mysql Jul : sbtest1.ibd [root@zlm1 :: /data/backup/--06_10--]
#ls -l /data/mysql/mysql3306/data/zlm | grep test_flashbk.ibd
-rw-r----- mysql mysql Jul : test_flashbk.ibd
root@localhost:mysql3306.sock [(none)]>alter table sysbench.sbtest1 import tablespace;
Query OK, rows affected, warning (1.73 sec) root@localhost:mysql3306.sock [(none)]>show warnings;
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | | InnoDB: IO Read error: (, No such file or directory) Error opening './sysbench/sbtest1.cfg', will attempt to import without schema verification |
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------+
row in set (0.00 sec) root@localhost:mysql3306.sock [(none)]>alter table zlm.test_flashbk import tablespace;
Query OK, rows affected, warning (1.01 sec) root@localhost:mysql3306.sock [(none)]>show warnings;
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | | InnoDB: IO Read error: (, No such file or directory) Error opening './zlm/test_flashbk.cfg', will attempt to import without schema verification |
+---------+------+--------------------------------------------------------------------------------------------------------------------------------------------------+
row in set (0.00 sec) root@localhost:mysql3306.sock [(none)]>select count(*) from sysbench.sbtest1;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.25 sec) root@localhost:mysql3306.sock [(none)]>select count(*) from zlm.test_flashbk;
+----------+
| count(*) |
+----------+
| |
+----------+
row in set (0.10 sec) //The warnings show that tthe message about missing of .cfg file what rally doesn't matter.
//The .cfg file is usually create by executing "flush table ... for export;"
//We can benifit in crash recover scenario with the support of ignoring the missing of .cfg in transportable tablespace feature.
- mysqlfrm is a tool of mysql-utilities which is specialized in analyzing .frm files in order to gain the missing structure of tables.
- mysqlfrm provides two modes of operation:1. connecting to server with "--server"(defaut mode);2. create a new instance with "--basedir".
- With the help of parameter "--diagnostic",we can even get information from a .frm file without installing a MySQL server on the host.
- We cannot get character set and collation information on tables if we forget to use "--server" option.
- Of course,in order to use transportable tablespace properly,the parameter "innodb_file_per_table=1" is necessary.
- In my case above,the structure of table about char datatype changed accidently which I'm still baffled with.
- Also,we can restore these table to any other server like transportable tablespace does.
基于Xtrabackup恢复单个innodb表的更多相关文章
- 从完整备份恢复单个innodb表
现在大多数同学在线上采取的备份策略都是xtrabackup全备+binlog备份,那么当某天某张表意外的删除那么如何从xtrabackup全备中恢复呢?从mysql 5.6版本开始,支持可移动表空间( ...
- MySQL 备份恢复(导入导出)单个 innodb表
MySQL 备份恢复单个innodb表呢,对于这种恢复我们我们很多朋友都不怎么了解了,下面一起来看一篇关于MySQL 备份恢复单个innodb表的教程 在实际环境中,时不时需要备份恢复单个或多个表(注 ...
- xtrabackup 恢复单个表【转】
一.安装与备份 1. 下载安装XtraBackup$wget http://www.percona.com/redir/downloads/XtraBackup/LATEST/binary/tarba ...
- 【理论篇】Percona XtraBackup 恢复单表
小明在某次操作中,误操作导致误删除了某个表,需要立即进行数据恢复. 如果是数据量较小的实例,并且有备份,即便是全备,做一次全量恢复,然后单表导出导入,虽然麻烦一点,却也花不了多少时间:如果是数据量大的 ...
- mysql如何从全备文件中恢复单个库或者单个表
mysql如何从全备文件中恢复单个库或者单个表 在mysql dba的日常实际工作中,一个实例下有多个库,而我们常见的备份就是全库备份.那么问题就来了,如果需要恢复单个库或者单个表,怎么办了,网上有很 ...
- 从xtraback 备份文件中 单独恢复一张 innodb 表
从xtraback 备份文件中 单独恢复一张 innodb 表 http://blog.sina.com.cn/s/blog_445e807b0101dbgw.html 能够恢复一张表的前提是独立表空 ...
- 从MySQL全备文件中恢复单个库或者单个表
从MySQL全备文件中恢复单个库或者单个表 提取建库语句 sed -n '/^-- Current Database: db_cms/,/^-- Current Database: `/p' back ...
- 基于xtrabackup实现mysql备份还原
简介 Xtrabackup2.2版之前包括4个可执行文件: innobackupex: Perl 脚本 xtrabackup: C/C++ 编译的二进制 xbstream: 支持并发写的流文件格式 x ...
- 14.1.2 InnoDB表最佳实践:
14.1.2 Best Practices for InnoDB Tables InnoDB表最佳实践: 这个章节描述使用InnoDB表最佳实践: 1.指定一个主键用于每个表使用最多查询的列或者多列, ...
随机推荐
- RadControl使用相同的Theme
我們僅須對兩個地方加一些程式碼,就可使所有的RadControl擁用相的Theme,如此一下不但可使Ap內布景主題一致,設計者亦不需要對每個控件做字型,顏色,大小等等瑣碎的設計. App.Xaml.c ...
- pat1031. Hello World for U (20)
1031. Hello World for U (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Giv ...
- Apache-ant安装以及环境变量配置、验证
(一)安装 ant 下载地址: http://ant.apache.org/ 根据自己电脑下载对应版本 下载完成以后,可自行解压到自己常用的盘中,但是要记住解压到哪里了,以便后续的环境变量配置 ...
- gof23 适配器模式
namespace Adapter { class Program { static void Main(string[] args) { //原实现 ClassBase customa = new ...
- Js仿腾讯微博效果
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- linux文件按照行数切割
公司小站的nginx服务器日志一直没有管理 到发现的时候已经有50G+的logs文件 查看起来十分不便 只能将其切割 接下来分享 具体方法 split -l 5000(行数) -a 5(增加文件名上限 ...
- Dynamics CRM用户创建后自动添加到团队报错
前两天在实现一项需求——用户创建后自动添加到一个叫做“全体员工”的团队的时候,遇到了一个奇怪的错误,CRM的错误日志只有一句简单的“Generic SQL error.”.一般遇到这个错误处理都非比较 ...
- JSP中的Property 'name' not found on type java.lang.String
如果是在forEach中出现. 那么看下items里是不是没有el表达式,只是个字符串. 今天犯了好几次. 特此记录
- ScrollView监听滑动到顶部和底部的方法
不需要监听滑动位置,只需要重写ScrollView的onOverScrolled和stopNestedScroll方法就可以了 public class ReadScrollView extends ...
- 聪明的Azure CDN,帮你找到云端捷径
你知道吗?身处上海和纽约的两个用户同时通过网络收看“春晚”直播,纽约播放得可能比上海还要更流畅,这当然不是因为纽约距离北京的直播机房更近或者网速更快,而是因为大年夜在大洋彼岸围观“春晚”的观众相对较少 ...