Mysqlfrm查看Mysql表结构
The mysqlfrm utility is designed as a recovery tool that reads .frm files and produces equivalent CREATE statements from the table definition data found in the file. In most cases, the generated CREATE statement is usable for recreating the table on another server, or for extended diagnostics. However, some features are not saved in the .frm files and therefore will be omitted. The exclusions include but are not limited to:
- foreign key constraints
- auto increment number sequences
一、下载
https://downloads.mysql.com/archives/utilities/
https://cdn.mysql.com/archives/mysql-utilities/mysql-utilities-1.6.5.tar.gz
二、安装
[root@db01 soft]# tar xvf mysql-utilities-1.6.5.tar.gz -C /usr/local
[root@db01 local]# ln -s mysql-utilities-1.6.5 mysql-utilities
[root@db01 mysql-utilities]# cd mysql-utilities
[root@db01 mysql-utilities]# python ./setup.py build
[root@db01 mysql-utilities]# python ./setup.py install
三、Mysqlfrm参数
--basedir=BASEDIR the base directory for the server
--server=SERVER connection information for the server in the form:
<user>[:<password>]@<host>[:<port>][:<socket>] or
<login-path>[:<port>][:<socket>] (optional) - if
provided, the storage engine and character set
information will be validated against this server.
--diagnostic read the frm files byte-by-byte to form the CREATE
statement. May require the --server or --basedir
options to decipher character set information
--user=USER user account to launch spawned server. Required if
running as root user. Used only in the default mode.
四、Mysqlfrm查看表结构
[root@db01 ~]# mysqlfrm --diagnostic /data/mysql/data/gtid/t.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 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/data/gtid/t.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement:
CREATE TABLE `gtid`.`t` (
`id` int(11) DEFAULT NULL,
`name` varchar(10) DEFAULT NULL
) ENGINE=InnoDB;
#...done.
读取gtid目录下所有的.frm文件:
[root@db01 ~]# mysqlfrm --diagnostic /data/mysql/data/gtid