1.诊断该数据库下的表结构。
[root@mysql1 ~]# mysqlfrm --diagnostic /mysql/mysql3306/test
# 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 /mysql/mysql3306/test/test1.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement:
CREATE TABLE `test`.`test1` (
`id` int(11) DEFAULT NULL,
`name` varchar(10) DEFAULT NULL
) ENGINE=InnoDB;
# Reading .frm file for /mysql/mysql3306/test/test2.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement:
CREATE TABLE `test`.`test2` (
`id` int(11) DEFAULT NULL,
`name` varchar(20) DEFAULT NULL
) ENGINE=InnoDB;
2.检查test数据库下:frm 生成建表语句。
解析test数据库下所有表的结构。
mysqlfrm --server=root:rootroot@localhost:3306 /mysql/mysql3306/test/ --port=3308 --user=mysql
或者:解析单个表的frm结构。
mysqlfrm --server=root:rootroot@localhost:3306 /mysql/mysql3306/test/test2.frm /mysql/mysql3306/test/test1.frm --port=3308 --user=mysql
WARNING: Using a password on the command line interface can be insecure.
# Source on localhost: ... connected.
# Spawning server with --user=mysql.
# Starting the spawned server on port 3308 ... done.
# Reading .frm files
# Reading the test1.frm file.
# CREATE statement for /mysql/mysql3306/test/test1.frm:
#
CREATE TABLE `test`.`test1` (
`id` int(11) DEFAULT NULL,
`name` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
# Reading the test2.frm file.
# CREATE statement for /mysql/mysql3306/test/test2.frm:
CREATE TABLE `test`.`test2` (
`id` int(11) DEFAULT NULL,
`name` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
#...done.
总结:
通常.frm 文件是二进制的无法直接看里面的内容,通过mysqlfrm 工具可以很方便的查看表的结构,同时可以检查文件是否损坏。