Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to delete a large table in Mysql

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article is about how to delete the big table in Mysql. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it with the editor.

[solution]

1. Reduce mysql DDL time through hard links and speed up lock release

two。 Delete files in segments through truncate to avoid IO hang

[production case]

For a pair of mysql master / slave, insufficient space is found when the master database writes too much, so it is necessary to urgently clean up the discarded large table, but it cannot affect the application access response:

$ll / u01/mysql/data/test/tmp_large.ibd

-rw-r-- 1 mysql dba 289591525376 Mar 30 2012 tmp_large.ibd

The process of deleting and changing large tables in 270GB is as follows:

# (make grayscale first)

Ln tmp_large.ibd / u01/bak/tmp_tbl.ibd # establish hard links

-rw-r-- 2 mysql dba 289591525376 Mar 30 2012 tmp_large.ibd

Set session sql_log_bin=0

# not counting bin log to save performance and prevent inconsistencies between master and backup

Desc test.tmp_large

Drop table test.tmp_large

Query OK, 0 rows affected (10.46 sec) mysql-uroot-e "start slave;"

Cd / u01Compact bakterScreen-S weixi_drop_table for i in `seq 270-1 1`

Do sleep 2 × truncate-s ${I} G tmp_tbl.ibd;done

Rm-rf tmp_tbl.ibd

[performance comparison]

Once in the middle ctrl-C, you can see the comparison of io before and after truncate, which basically has little impact.

The file size was also updated successfully

[introduction to tools]

Truncate-shrink or extend the size of a file to the specified size

# from the coreutils toolset

Wget ftp.gnu.org/gnu/coreutils/coreutils-8.9.tar.gz

Tar-zxvf coreutils-8.9.tar.gz

Cd coreutils-8.9. / configure

Make

Sudo cp src/truncate / usr/bin/

The above is how to delete the big table in Mysql. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report