我在 subscribers_table 中有大约 4,200,000 条记录的大量数据记录,当我通过电子邮件选择一个用户时需要很长时间,现在我不想删除这些记录并且我需要处理单独的表,如 subscribers_table1,subscribers_table2,。 .., subscribers_table42
现在我需要在 mysql 中定义过程 将 subscribers_table 中的数据洞移动到单独的表 subscribers_table1, subscribers_table2, ..., subscribers_table42 以下代码为伪代码:
table_number = 1
function table_to_migrate_into_separate_tables():
//this loop to read 100,000 record and move to next 100,000 until the end of table
for every 100,000 record in subscribers_table:
//this to create table with nambe (original name + table_number)
Create table("subscribers_table" + table_number)
//this to move 100,000 record only to the created table
Move 100,000 record to table("subscribers_table"+ table_number)
//increase table number to be unique
table_number ++
//this check if subscribers_table has migrate all the records into seperate table then break loop and finish
if subscribers_table has finish:
Break loop
最佳答案
这叫做 Partitionning ,MySQL 可以为您完成这项工作:
ALTER TABLE your_table PARTITION BY KEY(some_column_here) PARTITIONS 40;
但是,4M 行毕竟不是那么,也许您缺少的只是电子邮件
上的索引。
关于mysql - 如何将subscribers表中的400万条记录迁移到mysql中的40个表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24610458/