mysqlfrm可基于frm文件生成对应的表结构。常用于数据恢复场景。

其有两种操作模式。

1. 创建一个临时实例来解析frm文件。

2. 使用诊断模式解析frm文件。

以下表进行测试,看看,

1.  mysqlfrm解析的结果与原生表结构的区别。

2.  两种操作模式解析结果的不同。

mysql> show create table t_child\G
*************************** 1. row ***************************
Table: t_child
Create Table: CREATE TABLE `t_child` (
`child_id` int(11) NOT NULL AUTO_INCREMENT,
`parent_id` int(11) DEFAULT NULL,
PRIMARY KEY (`child_id`),
KEY `parent_id` (`parent_id`),
CONSTRAINT `t_child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `t_parent` (`parent_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

首先看看第一种操作模式。

既然是创建临时实例,肯定需要知道软件所在的位置,有两种方式。

1. 指定--basedir

$ mysqlfrm --basedir=/usr/local/mysql7 /tmp/t_child.frm --port=3333

# Starting the spawned server on port 3333 ... done.
# Reading .frm files
#
# Reading the t_child.frm file.
#
# CREATE statement for /tmp/t_child.frm:
# CREATE TABLE `tmp`.`t_child` (
`child_id` int(11) NOT NULL AUTO_INCREMENT,
`parent_id` int(11) DEFAULT NULL,
PRIMARY KEY (`child_id`),
KEY `parent_id` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 #...done.

2. 指定--server

$ mysqlfrm --server=root:123456@127.0.0.1:3307 /tmp/t_child.frm  --port=2323

WARNING: Using a password on the command line interface can be insecure.
# Source on 127.0.0.1: ... connected.
# Starting the spawned server on port 2323 ... done.
# Reading .frm files
#
# Reading the t_child.frm file.
#
# CREATE statement for /tmp/t_child.frm:
# CREATE TABLE `tmp`.`t_child` (
`child_id` int(11) NOT NULL AUTO_INCREMENT,
`parent_id` int(11) DEFAULT NULL,
PRIMARY KEY (`child_id`),
KEY `parent_id` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 #...done.

注意,指定--server和--basedir没有多大区别,主要也是为了获取basedir。

从上面的输出可以看到,相对于其原生表结构,打印出的表结构,

1. 没有自增主键的序列信息。

2. 没有外键约束。

再来看看通过诊断模式解析的结果。

$ mysqlfrm --diagnostic /tmp/t_child.frm

# 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 es
pecially 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 /tmp/t_child.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement: CREATE TABLE `tmp`.`t_child` (
`child_id` int(11) NOT NULL AUTO_INCREMENT,
`parent_id` int(11) DEFAULT NULL,
PRIMARY KEY `PRIMARY` (`child_id`),
KEY `parent_id` (`parent_id`)
) ENGINE=InnoDB; #...done.

相对于通过临时实例来解析frm文件,通过诊断模式解析的结果没有字符集。

其它选项

--show-stats:打印frm文件信息

$ mysqlfrm --diagnostic /tmp/t_child.frm --show-stats
# 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 /tmp/t_child.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement: CREATE TABLE `tmp`.`t_child` (
`child_id` int(11) NOT NULL AUTO_INCREMENT,
`parent_id` int(11) DEFAULT NULL,
PRIMARY KEY `PRIMARY` (`child_id`),
KEY `parent_id` (`parent_id`)
) ENGINE=InnoDB; # File Statistics:
# Last Modified : Thu Jul 12 23:36:12 2018
# Creation Time : Thu Jul 12 23:36:25 2018
# Last Accessed : Thu Jul 12 23:36:42 2018
# Mode : 33188
# Size : 8608 # Table Statistics:
# Engine : INNODB
# frm Version : 9
# MySQL Version : 5.7.22
# frm File_Version : 5
# IO_SIZE : 4096
# Def Partition Engine : None #...done.

注意:

如果使用方式1解析frm文件出现问题,可打开debug模式,如,

$ mysqlfrm --server=root:123456@127.0.0.1:3307 /tmp/t_child.frm --port=2323 -vvv

WARNING: Using a password on the command line interface can be insecure.
# Source on 127.0.0.1: ... connected.
# Checking read access to .frm files
# Creating a temporary datadir = /tmp/tmpA4tVug
# Starting the spawned server on port 2323 ...
# Cloning the MySQL server located at /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64.
# Configuring new instance...
# Locating mysql tools...
# Location of files:
# mysqld: /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64/bin/mysqld
# mysqladmin: /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64/bin/mysqladmin
# Setting up empty database and mysql tables...
2018-07-13T00:36:29.211443Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-07-13T00:36:30.209454Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-07-13T00:36:30.335785Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-07-13T00:36:30.441182Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c90ecb11-8634-11e
8-a908-00163e0cf2bb.2018-07-13T00:36:30.443663Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-07-13T00:36:30.444160Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
# Starting new instance of the server...
# Startup command for new server:
/usr/local/mysql-5.7.22-linux-glibc2.12-x86_64/bin/mysqld --no-defaults --basedir=/usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 --datadir=/tmp/tmpA4tVug --pid-file=/tmp/tmpA4tVug/clone.pid
--port=2323 --server-id=101 --socket=/tmp/tmpA4tVug/mysql.sock --tmpdir=/tmp/tmpA4tVug# Testing connection to new instance...
2018-07-13T00:36:33.643490Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-07-13T00:36:33.643662Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2018-07-13T00:36:33.643709Z 0 [Note] /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64/bin/mysqld (mysqld 5.7.22) starting as process 18776 ...
2018-07-13T00:36:33.650009Z 0 [Note] InnoDB: PUNCH HOLE support available
2018-07-13T00:36:33.650037Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-07-13T00:36:33.650042Z 0 [Note] InnoDB: Uses event mutexes
2018-07-13T00:36:33.650046Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
2018-07-13T00:36:33.650050Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-07-13T00:36:33.650054Z 0 [Note] InnoDB: Using Linux native AIO
2018-07-13T00:36:33.650346Z 0 [Note] InnoDB: Number of pools: 1
2018-07-13T00:36:33.650451Z 0 [Note] InnoDB: Using CPU crc32 instructions
2018-07-13T00:36:33.652049Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2018-07-13T00:36:33.676202Z 0 [Note] InnoDB: Completed initialization of buffer pool
2018-07-13T00:36:33.679296Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2018-07-13T00:36:33.690571Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2018-07-13T00:36:33.722958Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2018-07-13T00:36:33.723014Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2018-07-13T00:36:33.862563Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2018-07-13T00:36:33.863553Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2018-07-13T00:36:33.863565Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2018-07-13T00:36:33.863831Z 0 [Note] InnoDB: Waiting for purge to start
2018-07-13T00:36:33.914001Z 0 [Note] InnoDB: 5.7.22 started; log sequence number 2589156
2018-07-13T00:36:33.914376Z 0 [Note] Plugin 'FEDERATED' is disabled.
2018-07-13T00:36:33.920024Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2018-07-13T00:36:33.920043Z 0 [Note] Server hostname (bind-address): '*'; port: 2323
2018-07-13T00:36:33.920081Z 0 [Note] IPv6 is available.
2018-07-13T00:36:33.920088Z 0 [Note] - '::' resolves to '::';
2018-07-13T00:36:33.920106Z 0 [Note] Server socket created on IP: '::'.
2018-07-13T00:36:33.920400Z 0 [Note] InnoDB: Loading buffer pool(s) from /tmp/tmpA4tVug/ib_buffer_pool
2018-07-13T00:36:33.922124Z 0 [Note] InnoDB: Buffer pool(s) load completed at 180713 8:36:33
2018-07-13T00:36:33.923975Z 0 [Warning] Insecure configuration for --pid-file: Location '/tmp' in the path is accessible to all OS users. Consider choosing a different directory.
2018-07-13T00:36:33.931917Z 0 [Note] Event Scheduler: Loaded 0 events
2018-07-13T00:36:33.932165Z 0 [Note] /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64/bin/mysqld: ready for connections.
Version: '5.7.22' socket: '/tmp/tmpA4tVug/mysql.sock' port: 2323 MySQL Community Server (GPL)
# trying again...
# Success!
# Setting the root password...
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
# Connection Information:
# -uroot -proot --socket=/tmp/tmpA4tVug/mysql.sock
#...done.
# Connecting to spawned server
2018-07-13T00:36:34.461329Z 2 [Note] Aborted connection 2 to db: 'unconnected' user: 'root' host: 'localhost' (Got an error reading communication packets)
done.
# Reading .frm files
#
# Reading the t_child.frm file.
# Changing engine for .frm file /tmp/tmpA4tVug/tmp_temp/t_child.frm:
# Skipping to header at : 2
# General Data from .frm file:
{'IO_SIZE': 4096,
'MYSQL_VERSION_ID': 50722,
'avg_row_length': 0,
'charset_low': 0,
'create_options': 8,
'db_create_pack': 2,
'default_charset': 8,
'default_part_eng': 0,
'extra_size': 31,
'frm_file_ver': 5,
'frm_version': 9,
'key_block_size': 0,
'key_info_length': 60,
'key_length': 706,
'legacy_db_type': 'INNODB',
'length': 12288,
'max_rows': 0,
'min_rows': 0,
'rec_length': 9,
'row_type': 0,
'table_charset': 8,
'tmp_key_length': 706}
# Engine string: InnoDB
# Server version in file: 5.7.22
#
# CREATE statement for /tmp/t_child.frm:
# CREATE TABLE `tmp`.`t_child` (
`child_id` int(11) NOT NULL AUTO_INCREMENT,
`parent_id` int(11) DEFAULT NULL,
PRIMARY KEY (`child_id`),
KEY `parent_id` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 # Shutting down spawned server
# Removing the temporary datadir
2018-07-13T00:36:34.502751Z 0 [Note] Giving 0 client threads a chance to die gracefully
2018-07-13T00:36:34.502772Z 0 [Note] Shutting down slave threads
2018-07-13T00:36:34.502777Z 0 [Note] Forcefully disconnecting 0 remaining clients
2018-07-13T00:36:34.502785Z 0 [Note] Event Scheduler: Purging the queue. 0 events
2018-07-13T00:36:34.502916Z 0 [Note] Binlog end
2018-07-13T00:36:34.502973Z 0 [Note] Shutting down plugin 'ngram'
2018-07-13T00:36:34.502979Z 0 [Note] Shutting down plugin 'ARCHIVE'
2018-07-13T00:36:34.502982Z 0 [Note] Shutting down plugin 'partition'
2018-07-13T00:36:34.502985Z 0 [Note] Shutting down plugin 'BLACKHOLE'
2018-07-13T00:36:34.502989Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2018-07-13T00:36:34.503028Z 0 [Note] Shutting down plugin 'CSV'
2018-07-13T00:36:34.503032Z 0 [Note] Shutting down plugin 'MEMORY'
2018-07-13T00:36:34.503036Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2018-07-13T00:36:34.503041Z 0 [Note] Shutting down plugin 'MyISAM'
2018-07-13T00:36:34.503049Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
2018-07-13T00:36:34.503052Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2018-07-13T00:36:34.503055Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2018-07-13T00:36:34.503058Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2018-07-13T00:36:34.503061Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2018-07-13T00:36:34.503064Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2018-07-13T00:36:34.503066Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2018-07-13T00:36:34.503069Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2018-07-13T00:36:34.503072Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2018-07-13T00:36:34.503075Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2018-07-13T00:36:34.503077Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2018-07-13T00:36:34.503080Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2018-07-13T00:36:34.503083Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2018-07-13T00:36:34.503086Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2018-07-13T00:36:34.503088Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2018-07-13T00:36:34.503091Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2018-07-13T00:36:34.503094Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
2018-07-13T00:36:34.503096Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2018-07-13T00:36:34.503099Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2018-07-13T00:36:34.503102Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2018-07-13T00:36:34.503105Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2018-07-13T00:36:34.503108Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2018-07-13T00:36:34.503111Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2018-07-13T00:36:34.503113Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2018-07-13T00:36:34.503116Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
2018-07-13T00:36:34.503119Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2018-07-13T00:36:34.503122Z 0 [Note] Shutting down plugin 'INNODB_CMP'
2018-07-13T00:36:34.503124Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2018-07-13T00:36:34.503127Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2018-07-13T00:36:34.503130Z 0 [Note] Shutting down plugin 'INNODB_TRX'
2018-07-13T00:36:34.503132Z 0 [Note] Shutting down plugin 'InnoDB'
2018-07-13T00:36:34.503182Z 0 [Note] InnoDB: FTS optimize thread exiting.
2018-07-13T00:36:34.503325Z 0 [Note] InnoDB: Starting shutdown...
#...done.
[test@slowtech ~]$ 2018-07-13T00:36:34.603656Z 0 [Note] InnoDB: Dumping buffer pool(s) to /tmp/tmpA4tVug/ib_buffer_pool
2018-07-13T00:36:34.603717Z 0 [ERROR] InnoDB: Cannot open '/tmp/tmpA4tVug/ib_buffer_pool.incomplete' for writing: No such file or directory
2018-07-13T00:36:35.517978Z 0 [Note] InnoDB: Shutdown completed; log sequence number 2589175
2018-07-13T00:36:35.518034Z 0 [Note] Shutting down plugin 'sha256_password'
2018-07-13T00:36:35.518040Z 0 [Note] Shutting down plugin 'mysql_native_password'
2018-07-13T00:36:35.518200Z 0 [Note] Shutting down plugin 'binlog'
2018-07-13T00:36:35.518563Z 0 [Note] Unable to delete pid file: No such file or directory
2018-07-13T00:36:35.518568Z 0 [Note] /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64/bin/mysqld: Shutdown complete

mysqlfrm的更多相关文章

  1. mysqlfrm初步使用

    这个工具也就是读取frm文件生成建表语句默认的模式是再生个实例,使用--basedir选项或指定--server选项来连接到已经安装的实例.这种过程不会改变原始的.frm文件.该模式也需要指定--po ...

  2. 使用mysqlfrm恢复frm表结构,获得建表语句

    1.mysqlfrm 是一个恢复性质的工具,用来读取.frm文件并从该文件中找到表定义数据生成CREATE语句. 下载链接:https://downloads.mysql.com/archives/u ...

  3. 使用mysqlfrm恢复frm表结构的方法

    1.mysqlfrm安装 由于mysqlfrm是mysql-utilities工具一部分,那么我们安装mysql-utilities即可,下载好对应的源码包,进行编译安装 shell> wget ...

  4. mysql-.frm,.myd,myi备份如何导入mysql

    .frm..myd..myi文件,也就是说是MySQL的原始数据文件,这三个文件分别是: .frm 表结构文件 .myd 表数据文件 .myi 表索引文件 方法,如下: 新建一个数据库 在my.ini ...

  5. 一次基于innobackupex备份及binlog的单表恢复操作

    [环境介绍] 系统环境:Red Hat Enterprise Linux Server release 7.0 (Maipo) + Server version: 5.7.18-log MySQL C ...

  6. MySQL Innodb数据库误删ibdata1后MySQL数据库的恢复案例

      上周,以前公司的同事朋友找我帮忙,看看能否帮忙恢复一个MySQL 数据库,具体情况为:数据库版本为MySQL 5.6(具体版本不清楚),也不清楚具体的数据库引擎; 没有数据库备份,只剩下数据库下面 ...

  7. 从xtrabackup备份恢复单表

    目前对MySQL比较流行的备份方式有两种,一种上是使用自带的mysqldump,另一种是xtrabackup,对于数据时大的环境,普遍使用了xtrabackup+binlog进行全量或者增量备份,那么 ...

  8. 从完整备份恢复单个innodb表

    现在大多数同学在线上采取的备份策略都是xtrabackup全备+binlog备份,那么当某天某张表意外的删除那么如何从xtrabackup全备中恢复呢?从mysql 5.6版本开始,支持可移动表空间( ...

  9. 利用.frm、.ibd恢复数据

    我们知道启用innodb_file_per_table选项后,单个表(InnoDB引擎)的数据和索引放入单独的文件中(.ibd),建表语句保存在.frm文件中本文假设192.168.85.132,33 ...

随机推荐

  1. (其他)用sublime text3编写的html网页用浏览器打开出现中文乱码的原理及解决方法(转)

    最近发现Hbuler比较难用,换成sublime text3了,用了以前没用过的软件,就要学习他的操作,刚上手就出了点问题. 解决方法就是sublime text3以utf8 with bom保存. ...

  2. Linux 中提高的 SSH 的安全性

    SSH 是远程登录 Linux 服务器的最常见的方式.且 SSH 登录的时候要验证的,相对来讲会比较安全.那只是相对,下面会介绍一些方式提高 SSH 的安全性 SSH 的验证 而SSH 登录时有两种验 ...

  3. Scrapy实现腾讯招聘网信息爬取【Python】

    一.腾讯招聘网 二.代码实现 1.spider爬虫 # -*- coding: utf-8 -*- import scrapy from Tencent.items import TencentIte ...

  4. 原生js :removeClass和addClass

    function removeClass(obj, aClass) { var re = new RegExp('\\b' + aClass + '\\b'); if (obj.className ! ...

  5. EOS与以太坊有哪些区别?

    以太坊是一个专门为开发和运行去中心化应用(DAPP)搭建的智能合约平台:EOS与以太坊类似,同样是基于智能合约和区块链而搭建.但是,从技术和设计理念等方面来看,这两者之间实际上存在明显的区别. 那么E ...

  6. Python的变量以及类型

    1.程序是用来处理数据的,变量就是用来存储数据的  num1 = 100 2.为了更充分的利用内存空间以及更有效率的管理内存,变量是有不同的类型 3.怎样知道一个变量的类型呢? 3.1 在python ...

  7. Win10 - MySQL-zip安装方法

    Win10 - MySQL-zip安装方法 安装步骤 1.下载,到MySQL官网:https://dev.mysql.com/downloads/mysql/ 2.解压安装包 解压下载的安装包,放到你 ...

  8. Pycharm用鼠标滚轮控制字体大小

    一.pycharm字体放大的设置 File —> setting —> Keymap —>在搜寻框中输入:increase —> Increase Font Size(双击) ...

  9. java 对象属性复制,将一个对象的属性值赋值给另一个对象, 属性名需要相同

    import org.springframework.beans.BeanUtils; BeanUtils.copyProperties(源对象, 目标对象);

  10. 【微信小游戏】【提审的坑】!#¥%&……&&……%¥#@@*()()&%%¥

    一.开通了虚拟支付后审核变慢 前两个版本是没有开通虚拟支付的,最快一个半小时就过审了.当时还在暗自嘲笑WX,条款很多,审核却那么松,甚至一度怀疑是不是没有审核直接放.然而第三版提审了之后,一个小时.两 ...