mysql最快的方式删除freebsd上的数据库内容?请帮助我尝试从navicat (400,000+行)删除,但在一个小时内.只有10万被删除了我没有phpmyadmin
发布于 2014-03-16 18:22:24
要删除表中的所有内容,请执行以下操作:
TRUNCATE TABLE table_you_want_to_nuke要删除某些行,您有两个选项:
- 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.
DELETE FROM your_table WHERE whatever_condition。您可能需要使用WHERE条件或LIMIT将其分解为块,这样就可以对其进行批处理,而不会永远陷入服务器瘫痪。哪个更好/更快取决于很多事情,主要是删除记录与保留记录的比率以及所涉及的索引数量。与往常一样,在运行数据库之前仔细测试,因为DELETE和TRUNCATE都会永久销毁数据。
https://stackoverflow.com/questions/22440620
复制相似问题