环境:
OS:Centos 6
[root@dev-env23 mysql-utilities-1.6.5]# python -V
Python 2.6.6
##################################获取建表ddl#########################
1.下载
下载地址:
https://downloads.mysql.com/archives/utilities/
下载的版本为:
mysql-utilities-1.6.5.tar.gz
2.解压
[root@dev-env23 soft]# tar -xvf mysql-utilities-1.6.5.tar.gz
[root@dev-env23 soft]# mv mysql-utilities-1.6.5 /opt/
3.安装
cd /opt/mysql-utilities-1.6.5
python ./setup.py install --record instfile.log
1) 使用选项 --record instfile.log 记录安装到系统的文件,在卸载时使用(手动删除).
2) 执行 python setup.py help 查看其他选项及帮助信息.
3) 所有命令会默认安装在 /usr/local/ 中.
4.通过frm文件获取到建表语句
[root@dev-env23 mysql-utilities-1.6.5]# mysqlfrm --diagnostic /home/mysql/data/db_yeemiao/ad.frm # 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 /home/mysql/data/db_yeemiao/ad.frm: # The .frm file is a TABLE. # CREATE TABLE Statement: CREATE TABLE `db_yeemiao`.`ad` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `article_id` bigint(20) DEFAULT NULL comment '文章id', `ad_name` varchar(400) NOT NULL comment '广告名称', `picture` varchar(600) NOT NULL comment '图片', `link_type` int(11) NOT NULL comment '0:外链,1:文章,2:帖子,3:无跳转', `content_link` varchar(2000) DEFAULT NULL comment '内容链接', `type` int(11) NOT NULL, `status` int(11) NOT NULL comment '是否启用:0-启用,1-禁用 默认启用', `is_del` bit(1) NOT NULL comment '是否删除:0未删除,1删除', `start_time` datetime NOT NULL comment '开始时间', `end_time` datetime NOT NULL comment '结束时间', `sort` int(11) NOT NULL comment '排序权重(越小越靠后)', `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '创建时间', `modify_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '修改时间', PRIMARY KEY `PRIMARY` (`id`) ) ENGINE=InnoDB; #...done.
获取到的表结构在新环境有可能因为字符集原因报如下错误,可以尝试修改索引字段大小解决
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
################数据恢复##########################
1.通过上面获取到的建表语句在新服务器上创建表
2.脱离表空间
alter table ad discard tablespace;
执行该命令后,对应的idb文件会自动删除掉
[root@host134 db_ym]# ls -al
total 16
drwx------ 2 mysql mysql 34 May 17 15:13 .
drwxrwxr-x 6 mysql mysql 238 May 17 14:52 ..
-rw-rw---- 1 mysql mysql 8556 May 17 15:12 ad.frm
-rw-rw---- 1 mysql mysql 67 May 17 14:38 db.opt
3.将crash服务器的表的idb文件拷贝到新服务器
cp /tmp/ad.ibd /opt/mysql56/data/db_ym/
chown -R mysql:mysql /opt/mysql56/data/db_ym/
4.加入表空间
alter table ad import tablespace;
5.验证
select count(1) from ad;
标签:comment,mysqlfrm,建表,ad,db,frm,mysql,NULL From: https://www.cnblogs.com/hxlasky/p/17410900.html