首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mysql最快的删除数据库内容的方法是什么?

Mysql最快的删除数据库内容的方法是什么?
EN

Stack Overflow用户
提问于 2014-03-16 17:59:59
回答 1查看 206关注 0票数 1

mysql最快的方式删除freebsd上的数据库内容?请帮助我尝试从navicat (400,000+行)删除,但在一个小时内.只有10万被删除了我没有phpmyadmin

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-16 18:22:24

要删除表中的所有内容,请执行以下操作:

代码语言:javascript
复制
TRUNCATE TABLE table_you_want_to_nuke

要删除某些行,您有两个选项:

  1. 遵循以下步骤:

代码语言:javascript
复制
- Create a temporary table using `CREATE TABLE the_temp_table LIKE current_table`
- Drop all of the indexes on the temp table.
- Copy the records you want to _keep_ with `INSERT INTO the_temp_table SELECT * FROM current_table WHERE ...`
- `TRUNCATE TABLE current_table`
- `INSERT INTO current_table SELECT * FROM the_temp_table`
- To speed this option up, you may want to drop all indexes from `current_table` before the final `INSERT INTO`, then recreate them after the `INSERT`. MySQL is much faster at indexing existing data than it is at indexing on the fly. 

  1. 您目前正在尝试的选项:DELETE FROM your_table WHERE whatever_condition。您可能需要使用WHERE条件或LIMIT将其分解为块,这样就可以对其进行批处理,而不会永远陷入服务器瘫痪。

哪个更好/更快取决于很多事情,主要是删除记录与保留记录的比率以及所涉及的索引数量。与往常一样,在运行数据库之前仔细测试,因为DELETETRUNCATE都会永久销毁数据。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22440620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档