mysqlfrm初步使用

这个工具也就是读取frm文件生成建表语句
默认的模式是再生个实例,使用--basedir选项或指定--server选项来连接到已经安装的实例。这种过程不会改变原始的.frm文件。该模式也需要指定--port选项来给再生的实例使用,该端口不能与现有的实例冲突。在读取.frm文件后,再生的实例将被关闭,所有的临时文件将被删除的。
诊断模式,需要指定 --diagnostic 选项。byte-by-byte读取.frm文件 尽可能多的恢复信息。该模式有更多的局限性,不能校验字符集;使用默认模式无法读取文件或者该服务器上没有安装MySQL实例就使用诊断模式。
安装
需要先安装mysql-connector-python

wget https://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.7-1.el6.x86_64.rpm
wget ftp://ftp.pbone.net/mirror/dev.mysql.com/pub/Downloads/MySQLGUITools/mysql-utilities-1.6.5-1.el6.noarch.rpm
wget ftp.pbone.net/mirror/dev.mysql.com/pub/Downloads/MySQLGUITools/mysql-utilities-extra-1.5.6-1.el6.noarch.rpm

使用需要指定.frm文件的路径,也可以指定一个目录,该目录下的所有.frm文件将被读取

 

默认模式
mysqlfrm --server=root:ocm123@localhost --user=root --port=3307  /data/mysql/ht/tb.frm
mysqlfrm --basedir=/usr  --port=3307--user=mysql /data/mysql/ht/tb.frm --show-stats

  

[root@redis01 ~]# mysqlfrm --server=root:ocm123@localhost --user=root --port=3307  /data/mysql/ht/tb.frm
WARNING: Using a password on the command line interface can be insecure.
# Source on localhost: ... connected.
# Spawning server with --user=root.
# Starting the spawned server on port 3307 ... done.
# Reading .frm files
#
# Reading the tb.frm file.
#
# CREATE statement for /data/mysql/ht/tb.frm:
#

CREATE TABLE `ht`.`tb` (
  `id` int(11) NOT NULL,
  `name` varchar(16) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

#...done.
[root@redis01 ~]# mysqlfrm --basedir=/usr  --port=3307 --user=mysql /data/mysql/ht/tb.frm  --show-stats
# Spawning server with --user=mysql.
# Starting the spawned server on port 3307 ... ERROR Attempting to stop failed spawned server.  Process id = 21404.
ERROR: Spawn server operation failed. Clone server error: Unable to communicate with new instance. Process id = 21404.. To diagnose, run the utility again and use the --verbose option to view the messages from the spawned server and correct any errors presented then run the utility again.
[root@redis01 ~]# mysqlfrm --basedir=/usr  --port=3307 --user=root /data/mysql/ht/tb.frm  --show-stats
# Spawning server with --user=root.
# Starting the spawned server on port 3307 ... done.
# Reading .frm files
#
# Reading the tb.frm file.
#
# CREATE statement for /data/mysql/ht/tb.frm:
#

CREATE TABLE `ht`.`tb` (
  `id` int(11) NOT NULL,
  `name` varchar(16) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

# File Statistics:
#         Last Modified : Sat Jun 30 10:06:11 2018
#         Creation Time : Sat Jun 30 10:06:11 2018
#         Last Accessed : Sat Jun 30 10:06:11 2018
#                  Mode : 33184
#                  Size : 8586

# Table Statistics:
#                Engine : HEAP
#           frm Version : 10
#         MySQL Version : 5.7.22
#      frm File_Version : 5
#               IO_SIZE : 4096
#  Def Partition Engine : None

#...done.
View Code
诊断模式
mysqlfrm --diagnostic /data/mysql/ht/tb.frm --show-stats

  

[root@redis01 ~]# mysqlfrm --diagnostic /data/mysql/ht/tb.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 /data/mysql/ht/tb.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement:

CREATE TABLE `ht`.`tb` (
  `id` int(11) NOT NULL, 
  `name` varchar(48) DEFAULT NULL, 
PRIMARY KEY `PRIMARY` (`id`)
) ENGINE=InnoDB;

# File Statistics:
#         Last Modified : Thu Jun 28 05:57:24 2018
#         Creation Time : Thu Jun 28 05:57:47 2018
#         Last Accessed : Fri Jun 29 23:01:23 2018
#                  Mode : 33184
#                  Size : 8586

# Table Statistics:
#                Engine : INNODB
#           frm Version : 10
#         MySQL Version : 5.7.22
#      frm File_Version : 5
#               IO_SIZE : 4096
#  Def Partition Engine : None

#...done.
View Code

选项
某些引擎表在默认模式下不可读取的。如PARTITION, PERFORMANCE_SCHEMA,必需在诊断模式下可读。
要在创建语句中改变存储引擎,可使用--new-storage-engine 选项。如果有指定该选项,同时必须指定--frmdir选项,该工具生成新的.frm文件,前缀为new_,并保存在--frmdir目录下。
关掉所有信息除了CREATE 语句和警告或错误信息,使用--quiet选项。
使用--show-stats 选项统计每个.frm文件信息。
使用--user 选项指定再生的实例以哪个权限运行。
如果再生的实例超过10秒启动,需调大--start-timeout 选项参数。

原文地址:https://www.cnblogs.com/omsql/p/9246302.html