首頁  >  文章  >  資料庫  >  使用mysqlfrm恢復frm表結構的方法

使用mysqlfrm恢復frm表結構的方法

一个新手
一个新手原創
2017-10-17 10:08:433582瀏覽

1、mysqlfrm安裝

-----------------------------

#由於mysqlfrm是mysql-utilities工具一部分,那麼我們安裝mysql-utilities即可,下載好對應的源碼包,進行編譯安裝。

shell> tar -xvzf mysql-utilities-1.6.4.tar.gz 
shell> cd mysql-utilities-1.6.4
shell> python ./setup.py build
shell> python ./setup.py install

安裝完成後,在對應的python執行目錄下,就能mysqlfrm等執行檔了。

2、mysqlfrm相關參數介紹

-------------------------- -----

--basedir :如 --basedir=/usr/local/percona-5.6.21
--server : 如 --server=user:password@192.168.1.100:3306
--diagnostic : 开启按字节模式来恢复frm结构
--user :启动MySQL用户,通过为mysql

3、mysqlfrm使用

---------------------- ---

使用--basedir模式恢復:

[ 16:35:29-root@br3cy1sw:~ ]# mysqlfrm --basedir=/usr/local/percona-5.6.21/ /root/t1.frm --port=3434 --user=mysql --diagnostic
# WARNING The --port option is not used in the --diagnostic mode.
# WARNING: The --user option is only used for the default mode.
# 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 /root/t1.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement:
CREATE TABLE `root`.`t1` (
`a` int(11) NOT NULL,
`b` int(11) DEFAULT NULL,
`c` int(11) DEFAULT NULL,
`d` varchar(600) DEFAULT NULL,
PRIMARY KEY `PRIMARY` (`a`),
KEY `idx_t1_bc` (`b`,`c`)
) ENGINE=InnoDB;
    #...done.

使用--server方式恢復:

[ 16:35:10-root@br3cy1sw:~ ]#mysqlfrm --server=user:password@192.168.1.100:3306 /root/t1.frm --port=3434 --user=mysql --diagnostic
WARNING: Using a password on the command line interface can be insecure.
# WARNING The --port option is not used in the --diagnostic mode.
# WARNING: The --user option is only used for the default mode.
# Source on 192.168.1.100: ... connected.
# 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 /root/t1.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement:
CREATE TABLE `root`.`t1` ( `a` int(11) NOT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL,
`d` varchar(200) COLLATE `utf8_general_ci` DEFAULT NULL,
PRIMARY KEY `PRIMARY` (`a`),
KEY `idx_t1_bc` (`b`,`c`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    #...done.

注意到沒有,使用--basedir恢復出來的varchar竟然是--server模式的3倍;這應該是mysqlfrm在使用basedir模式時,無法進行字元編碼校驗所致引起的。

再次看了下--server的檔案:(重點看標紅加粗的文字),建議:能用--server模式時,盡量使用--server同時保證提供mysqld環境與原生產環境的一致。

--server=server
Connection information for a server. Use this option or --basedir for the default mode.
 
If provided with the diagnostic mode, the storage engine and character set information are validated against this server.

以上是使用mysqlfrm恢復frm表結構的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn