這個工具也就是讀取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.
診斷模式 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.
選項
某些引擎表在默認模式下不可讀取的。如PARTITION, PERFORMANCE_SCHEMA,必需在診斷模式下可讀。
要在創建語句中改變存儲引擎,可使用--new-storage-engine 選項。如果有指定該選項,同時必須指定--frmdir選項,該工具生成新的.frm文件,前綴為new_,並保存在--frmdir目錄下。
關掉所有信息除了CREATE 語句和警告或錯誤信息,使用--quiet選項。
使用--show-stats 選項統計每個.frm文件信息。
使用--user 選項指定再生的實例以哪個權限運行。
如果再生的實例超過10秒啟動,需調大--start-timeout 選項參數。
