mysqlfrmを使用してfrmテーブル構造を復元する方法

7795 ワード

1、mysqlfrmインストール
mysqlfrmはmysql-utilitiesツールの一部ですので、mysql-utilitiesをインストールすればいいです.対応するソースパッケージをダウンロードし、コンパイルインストールを行います.
shell> wget https://cdn.mysql.com/archives/mysql-utilities/mysql-utilities-1.6.5.tar.gz

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モードを使用する場合、文字符号化チェックができないためであるはずです.
転載先:https://www.cnblogs.com/kcxg/p/11111042.html