使用mysqlfrm恢复frm表结构的方法


本文摘自PHP中文网,作者一个新手,侵删。

1、mysqlfrm安装

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

由于mysqlfrm是mysql-utilities工具一部分,那么我们安装mysql-utilities即可,下载好对应的源码包,进行编译安装。

1

2

3

4

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相关参数介绍

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

1

2

3

4

--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模式恢复:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

[ 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方式恢复:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

[ 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环境与原生产环境的一致。

1

2

3

4

--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表结构的方法 的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

mysql升级的最佳方法实例分享

mysql字段处理方法

php限制ip地址范围的实现方法

mysql开启慢查询日志的方法详解

保护mysql数据仓库的5个方法

mysql中的跨库关联查询方法实例

配置mysql主从分离的方法教程

mysql消除重复行方法分享

开启mysql慢查询日志的方法

php 限制某个ip访问的实现方法

更多相关阅读请进入《mysqlfrm》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...