MySQL how to delete temporary tables beginning #sql

 1. phenomenon

Found that lack of server disk space, large file screening by viewing the file is found to have several #sql beginning, and there is more than 100G and 10G file inspection.

2. reasons

If you quit in the middle of a MySQL ALTER TABLE operations (ALGORITHM = INPLACE), then you may leave a temporary table space occupied by the system. For example, when you add an index to a table (big table) interrupted midway, resulting in insufficient disk instance is caused when abnormal or kill so the situation is adding an index.

Note: these files can not be table space physical rm -f delete direct way, because the information is recorded in the shared table space ibdata's, after they are removed, an error occurs when a subsequent instance restart.

3. treatment

3.1 .frm exist and the same file name .ibd

If #sql -. * Ibd and #sql -. * Frm two files are present in the data directory, you can directly drop table. But pay attention to delete change when the table name.

/ * Delete, before the table name plus mysql50 #   * / 
root @testdb  01 : 42 : 57 >  DROP  TABLE `# mysql50 ## SQL - ib87 - 856 498 050 `;

Note: # mysql50 # is the file name prefix security coding introduced in MySQL 5.1. In addition, the table name because they do not conform to the naming convention, you want to execute the script requires the table name with the anti-quotation marks.

3.2 create a new table, delete the

Since the present embodiment and in the absence of the same file .frm .ibd name, and so a to create a spatial configuration corresponding ibd table (field names and index) the same table, and then copy the file to frm and consistent ibd file, then delete it.

Processing next screenshot # SQL -ib1516 - 2335726735.ibd document, the following steps:

a) create a with # sql-ib1516-2335726735 same table

root@testdb 08:47:35>create table company20191216 like  company;
Query OK, 0 rows affected (0.05 sec)

root@testdb 08:48:59>exit
Bye

b) copy of # sql-ib1516-2335726735.frm definition file

[root@db4 testdb]# cp -p  company20191216.frm  \#sql-ib1516-2335726735.frm

  c) Delete table

Using the -p step of the way when the copy, that is consistent with the original permissions and file permissions, owner and group are mysql, so you can read deleted directly in the database, if the authority does not, you must modify the file permissions.

root@testdb 08:49:54>drop table `#mysql50##sql-ib1516-2335726735`;
Query OK, 0 rows affected (6.65 sec)

At this point, 135G file has been deleted (in fact, another file #sql -821_2.frm file together also deleted )

 

 Note: 100G delete this table do not recommend directly deleted, but the process by creating hard links the way.

3.3 modify frm file name ibd file with the same name

When you delete a file on ibd step, one frm automatically deleted. To do this, try to deal with by modifying the frm file name and file name ibd consistent manner. Note, however, due to the uncertainty are the same structure, it may be abnormal modified, but if there is no deal with violence, usually can be successful. as follows:

a) modify frm file name and file names consistent ibd

[root@db4 testdb]# mv \#sql-a846_2.frm  \#sql-ib1570-121877015.frm

b) Delete table

root@testdb 01:41:06>DROP TABLE `#mysql50##sql-ib1570-121877015`;
Query OK, 0 rows affected (1.70 sec)

 

done!

In fact, there are other ways to deal with, we can self-test.

References: official documentation https://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting-datadict.html

Guess you like

Origin www.cnblogs.com/gjc592/p/12067691.html