MySQL索引的创建是缓慢的(在EC2)缓慢、索引、MySQL

2023-09-11 23:41:41 作者:请输入你的昵称

我有一个非常简单的表

requestparams (
  requestid varchar(64) NOT NULL,
  requestString text,
) ENGINE=MyISAM;

填充表包含LOAD DATA后,我改变模式,使请求ID的主键。

After populating the table with "LOAD DATA", I am changing the schema and making "requestid" the primary key.

有在此台11万行,数据大小小于2GB(该MYD文件的大小。)的索引文件的大​​小是围绕600M在过程的结束。

There are 11 million rows in this table and the data size is less than 2GB (size of the MYD file.) The index file size is around 600M at the end of the process.

创建索引只需要不到20分钟我的笔记本电脑。但是,当我跑的过程中对亚马逊的EC2(中实例),这个过程花了超过12小时。在整个过程中,磁盘是superbusy与IO等待的40-100%(如看到)。该CPU主要是空闲的。我不认为,在磁盘上的EC2是缓慢的。

Creating index takes less than 20 minutes on my laptop. But, when I ran the process on Amazon's EC2 (medium instance), the process took more than 12 hours. During entire process, the disk was superbusy with IO wait (as see by top) between 40-100%. The CPU was mostly idle. I don't think, the disk on EC2 are that slow.

在MySQL邮件列表,一些人建议更改服务器变量myisam_sort_buffer_size和放大器; myisam_max_sort_file_size。我将它们设置为512MB和放大器; 4GB的分别。但是,创建索引同样缓慢。事实上,由MySQL的内存使用量很少去超越40M。

On MySQL mailing list, some had suggested to change server variables myisam_sort_buffer_size & myisam_max_sort_file_size. I set them to 512MB & 4GB respectively. But index creation was equally slow. In fact, the memory usage by MySQL rarely went beyond 40M.

我该如何解决这个问题?

How do I fix this?

解决方法:增加key_buffer_size的帮助。我将这个值设置为1GB,并在4分钟内完成的过程。请确保您验证与新设置mysqladmin变量命令。

Solution: Increasing "key_buffer_size" helped. I set this value to 1GB and the process completed in 4 minutes. Make sure you verify the new settings with mysqladmin variables command.

推荐答案

您所收到的建议是正确的。我怀疑你做实际上并没有更改生效。尝试进行更改my.cnf中并重新启动服务器。

The suggestions you received are correct. I suspect the changes you made didn't actually take effect. Try making the changes in my.cnf and restart the server.