zoukankan      html  css  js  c++  java
  • 通过替换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的方式修改表结构。

  • 相关阅读:
    PHPCMS 商品浏览记录及其遇到的问题
    9月10日
    phpcms v9 数据库操作函数
    html Meta (整合)
    不同内核浏览器的差异以及浏览器渲染(转)
    position属性absolute与relative(转载)
    html规范,某人总结
    切图神器Assistor PS(PS外挂神器,亲证免费可用,下面是转载的使用方法)
    Android开发学习笔记:圆角的Button
    sublime text 2 技巧
  • 原文地址:https://www.cnblogs.com/hankyoon/p/5169738.html
Copyright © 2011-2022 走看看