简体   繁体   English

使用mysql innodb重命名巨型表时的最佳实践,当已存在同名表时

[英]Best practice with mysql innodb to rename huge table when table with same name already exist

I Use Mysql 5.5.. + INNODB and windows server. 我使用Mysql 5.5 .. + INNODB和Windows服务器。

The case(make it simple then real case): 案例(简单,然后真实案例):

I have 2 tables 1GB with name new_car and car table 1GB. 我有2个表1GB,名称为new_carcar表为1GB。

I to replace car table with new_car table every 10 hours not manually(auto by code) - important to do it fast(real website data). 我每10个小时用new_car表替换car表不是手动(自动代码) - 快速(真正的网站数据)很重要。

I read(say that drop its problem in innodb) : http://www.mysqlperformanceblog.com/2011/02/03/performance-problem-with-innodb-and-drop-table/ 我读过(比如在innodb中删除它的问题): http//www.mysqlperformanceblog.com/2011/02/03/performance-problem-with-innodb-and-drop-table/

solution1: 解决方法1:

DROP TABLE car;
RENAME TABLE new_car TO car;

Solution2(making drop in the end -maybe it not block the table to access that happen during drop): 解决方案2(最后放弃 - 可能不会阻止表访问丢弃期间发生的情况):

RENAME TABLE car TO temp_car;
RENAME TABLE new_car TO car;
DROP TABLE temp_car;

Solution3(Truncate delete fast the table and create empty table then maybe drop action after should be very fast): 解决方案3(截断快速删除表并创建空表然后可能会非常快速地删除操作):

TRUNCATE TABLE car;
DROP TABLE car;
RENAME TABLE new_car TO car; 

Solution4: Solution4:

RENAME TABLE car TO temp_car;
RENAME TABLE new_car TO car;
TRUNCATE TABLE temp_car;
DROP TABLE temp_car;

Which solution is the best and why or please write other better solution? 哪种解决方案最好,为什么还是请写其他更好的解决方案?

Thanks 谢谢

I don't understand why you would DROP the table. 我不明白为什么你会把桌子丢弃。 You always want those 2 tables and you'd (I'd assume be refilling up the New_Car table... 你总是想要那两张桌子而你(我假设要重新填满New_Car表...

RENAME TABLE car TO temp_car;
RENAME TABLE new_car TO car;
TRUNCATE TABLE temp_car;
RENAME TABLE temp_car TO new_car;
RENAME TABLE car TO temp_car, new_car TO car;
TRUNCATE TABLE temp_car;
DROP TABLE temp_car;

使用替换它需要5分钟或使用负载infile批量它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM