• 通过替换frm文件方式修改表结构


    版本:5.6.16

    在自己的虚拟环境中,测试创建一个表,表结构如下:
    mysql> drop table yoon_temp;
    Query OK, 0 rows affected (0.09 sec)


    mysql> show create table yoonG
    *************************** 1. row ***************************
           Table: yoon
    Create Table: CREATE TABLE `yoon` (
      `id` int(11) DEFAULT NULL,
      `name` varchar(20) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    1 row in set (0.00 sec)


    再创建一个相同的表结构,name varchar(30) 为30,并通过替换.frm来实现yoon表的字段修改:
    mysql> show create table yoon_tempG
    *************************** 1. row ***************************
           Table: yoon_temp
    Create Table: CREATE TABLE `yoon_temp` (
      `id` int(11) DEFAULT NULL,
      `name` varchar(30) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    1 row in set (0.00 sec)


    不小心直接删除yoon_temp.frm文件,无法替换,在数据库上删除yoon_temp提示表不存在:
    [root@hank-yoon yoon]# rm -rf yoon_temp.frm

    mysql> show tables;
    +----------------+
    | Tables_in_yoon |
    +----------------+
    | yoon           |
    +----------------+
    1 row in set (0.00 sec)


    删除表:
    mysql> drop table yoon_temp;
    ERROR 1051 (42S02): Unknown table 'yoon.yoon_temp'

    重新创建表:
    mysql> create table yoon_temp (id int,name varchar(30));
    ERROR 1813 (HY000): Tablespace for table '`yoon`.`yoon_temp`' exists. Please DISCARD the tablespace before IMPORT.

    mysql> alter table yoon_temp DISCARD tablespace;
    ERROR 1146 (42S02): Table 'yoon.yoon_temp' doesn't exist


    在目录下通过yoon.frm拷贝创建yoon_temp.frm
    [root@hank-yoon yoon]# cp  yoon.frm  yoon_temp.frm

    [root@hank-yoon yoon]# chown mysql.mysql yoon_temp.frm

    查看表:
    mysql> show tables;
    +----------------+
    | Tables_in_yoon |
    +----------------+
    | yoon           |
    | yoon_temp      |
    +----------------+
    2 rows in set (0.00 sec)


    mysql> show create table yoon_tempG
    *************************** 1. row ***************************
           Table: yoon_temp
    Create Table: CREATE TABLE `yoon_temp` (
      `id` int(11) DEFAULT NULL,
      `name` varchar(20) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    1 row in set (0.00 sec)


    mysql> drop table yoon_temp;
    Query OK, 0 rows affected (0.03 sec)

    重新创建再测试:
    mysql> create table yoon_temp (id int,name varchar(30));
    Query OK, 0 rows affected (0.02 sec)

    当表结构文件不小心删除时,可通过其他表结构来创建进行修复删除,表结构要相同,字段varcahr(xxx) xxx大小不同无所谓,也间接实现了通过替换frm的方式修改表结构。

  • 相关阅读:
    【GruntMate】一个让你更方便使用Grunt的工具
    HTML5小游戏【是男人就下一百层】UI美化版
    【Grunt】关于Grunt可视化的尝试
    在腾讯ubuntu云服务器上面部署asp.net core 2.1网站
    存储过程中执行动态Sql语句
    我的2016年总结
    程序员的成长阶梯和级别定义
    让IE8在win7下面能显示使用window.showmodaldialog弹出窗口的地址状态栏
    更改计算机名称后 导致 sql server 2008 R2 用windows账户不能附加的错误解决办法
    【转】通过js获取系统版本以及浏览器版本
  • 原文地址:https://www.cnblogs.com/hankyoon/p/5169738.html
Copyright © 2020-2023  润新知