简体   繁体   English

提高mysql速度?

[英]Improve mysql Speed?

I have mysql/php script running on my linux machine. 我的Linux机器上正在运行mysql / php脚本。 Its basically migrating files content to MySql table. 它基本上是将文件内容迁移到MySql表。 there are about 4400,000 Files, Account files each file`s content is places in a table in one row. 大约有4400,000个文件,帐户文件的每个文件的内容都放在表格的一行中。 It have been 14 hours and so far it have only done 300,000 Accounts. 已经14个小时了,到目前为止,它只完成了300,000个帐户。

At first it was very fast and was doing about 1000 files a second now it's slowed down to 50 files per second and the mysql process is consuming 95% of server CPU. 起初它速度非常快,每秒处理约1000个文件,现在每秒速度减慢到50个文件,并且mysql进程消耗了95%的服务器CPU。

Although The machine have multiple cores and I was thinking if its possible to allocate more then one core to mysql process which is consuming 95% of CPU. 尽管该计算机具有多个内核,但我一直在考虑是否有可能为mysql进程分配一个以上的内核,这会消耗95%的CPU。
Or is there any other way to make the process faster? 还是有其他方法可以使过程更快?

Thank you. 谢谢。

here is the script https://paste.ee/p/LZwlH#GHxpgqiUUPsVQFchdKVny2DEJQxaXH9V 这是脚本https://paste.ee/p/LZwlH#GHxpgqiUUPsVQFchdKVny2DEJQxaXH9V

Do not use the mysql_* API. 不要使用mysql_* API。 Switch to mysqli_* or PDO . 切换到mysqli_*PDO

Please provide these: 请提供以下内容:

SHOW CREATE TABLE
SHOW VARIABLES LIKE '%buffer%';

select * from players where p_name=' -- there is no need to select * , simply SELECT 1 . select * from players where p_name=' -无需选择* ,只需SELECT 1 Do you have an index on p_name ? 您在p_name上有索引吗? That is very important. 那很重要。

It smells like index updating, but can't be sure. 闻起来像是索引更新,但不能确定。

One way to speed up inserts is to 'batch' them -- 100 rows at a time will typically run 10 times as fast as 1 at a time. 加快插入速度的一种方法是“分批”插入-一次运行100行通常一次运行10倍。

Even better might be to use LOAD DATA . 更好的方法可能是使用LOAD DATA You may need to load into a temp table, then massage things before doing INSERT .. SELECT .. to put the data into the real table. 您可能需要加载到临时表中,然后在执行INSERT .. SELECT ..以便将数据放入实际表之前进行按摩。

Temporarily remove the INSERT from the procedure. 暂时从过程中删除INSERT See how fast it runs. 查看运行速度。 (You have not 'proven' that INSERT is the villain.) (您尚未“证明” INSERT是恶棍。)

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

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