简体   繁体   English

MySQL插入/更新/删除/选择有时会变慢

[英]MySQL insert/update/delete/select goes slow sometimes

As I am using InnoDB as a database engine, the query goes slower sometimes it takes 20 seconds or more often. 当我将InnoDB用作数据库引擎时,查询速度会变慢,有时需要20秒或更长时间。

I know the solution it can be done via my.conf to change the value of innodb_flush_log_at_trx_commit to 2 it can solve my problem I also want to do that but as I have shared hosting so they are not allowing me to do that. 我知道可以通过my.confinnodb_flush_log_at_trx_commit的值更改为2的解决方案,它也可以解决我的问题,但我也想这样做,但是由于我拥有共享主机,因此他们不允许我这样做。

MySQL version: 5.6.32-78.1 MySQL版本:5.6.32-78.1

I also tried with MySQL query 我也尝试过MySQL查询

mysql> SHOW VARIABLES LIKE 'innodb_flush_log_at_trx_commit';
+--------------------------------+-------+
| Variable_name                  | Value |
+--------------------------------+-------+
| innodb_flush_log_at_trx_commit | 1     |
+--------------------------------+-------+
1 row in set

And i tried this query 我尝试了这个查询

mysql> SET GLOBAL innodb_flush_log_at_trx_commit=2;

but it is also not allowing me too because I don't have super privileges to perform this action. 但这也不允许我,因为我没有执行此操作的超级特权。

I have database with 25 tables , and in 4 tables there are 4000+ records and in rest tables, there are below 100 records 我有25个表的数据库,在4个表中4000多个记录,在其余表中,有100个以下记录

So is there any other solution to speed up the query performance.? 因此,还有其他解决方案可以提高查询性能。 Any help will be appreciated. 任何帮助将不胜感激。

Use profile to check the cost time in each step; 使用配置文件检查每个步骤中的成本时间;

  1. set profiling=1;
  2. Run you query; 运行查询;
  3. Check the query: show profiles; 检查查询: show profiles;
  4. List the time cost: show profile block io,cpu for query N; 列出时间成本: show profile block io,cpu for query N;

Find the step which has the high Duration 找到Duration的步骤

It shows like this 像这样显示 型材 清单

Possible problem: Index, Order by, File sort, Use temp table.. 可能的问题:索引,排序依据,文件排序,使用临时表。

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

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