Modify the table structure by replacing the frm file

Source: Internet
Author: User
Tags virtual environment

Version: 5.6.16

In your own virtual environment, the test creates a table with the following table structure:
mysql> drop table yoon_temp;
Query OK, 0 rows affected (0.09 sec)


Mysql> Show CREATE TABLE Yoon\g
1. Row ***************************
Table:yoon
Create table:create Table ' Yoon ' (
' id ' int (one) DEFAULT NULL,
' Name ' varchar (DEFAULT NULL)
) Engine=innodb DEFAULT Charset=utf8
1 row in Set (0.00 sec)


Create an identical table structure, name varchar (30) to 30, and modify the field of the Yoon table by replacing the. FRM:
Mysql> Show CREATE TABLE Yoon_temp\g
1. Row ***************************
Table:yoon_temp
Create table:create Table ' yoon_temp ' (
' id ' int (one) DEFAULT NULL,
' Name ' varchar (+) DEFAULT NULL
) Engine=innodb DEFAULT Charset=utf8
1 row in Set (0.00 sec)


Accidentally delete the yoon_temp.frm file directly, cannot be replaced, delete the Yoon_temp prompt table on the database does not exist:
[Email protected] yoon]# RM-RF yoon_temp.frm

Mysql> Show tables;
+----------------+
| Tables_in_yoon |
+----------------+
| Yoon |
+----------------+
1 row in Set (0.00 sec)


To delete a table:
mysql> drop table yoon_temp;
ERROR 1051 (42S02): Unknown table ' Yoon.yoon_temp '

Re-create the table:
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


Create yoon_temp.frm with yoon.frm copy under directory
[email protected] yoon]# CP yoon.frm YOON_TEMP.FRM

[Email protected] yoon]# chown mysql.mysql yoon_temp.frm

View table:
Mysql> Show tables;
+----------------+
| Tables_in_yoon |
+----------------+
| Yoon |
| Yoon_temp |
+----------------+
2 rows in Set (0.00 sec)


Mysql> Show CREATE TABLE Yoon_temp\g
1. Row ***************************
Table:yoon_temp
Create table:create Table ' yoon_temp ' (
' id ' int (one) DEFAULT NULL,
' Name ' varchar (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)

Re-create the re-test:
Mysql> CREATE TABLE yoon_temp (ID int,name varchar (30));
Query OK, 0 rows affected (0.02 sec)

When the table structure file is accidentally deleted, can be created through the other table structure to repair the deletion, the table structure is the same, the field Varcahr (XXX) XXX size difference does not matter, also indirectly implemented by replacing the FRM way to modify the table structure.

Modify the table structure by replacing the frm file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.