MySQL 查询卡在队列中成为瓶颈

发布于 2024-09-12 15:58:54 字数 2469 浏览 3 评论 0原文

最近,有时我无法打开我的网站。

我使用 VPS 进行托管。

当我执行 mytop 时,

它向我显示:

       User         Host/IP         DB      Time    Cmd Query or State                                                                                                                             
      --      ----         -------         --      ----    --- ----------                                                                                   
   12512   xxx       localhost xxx        39  Query SELECT * FROM user WHERE no = '12341'                                                                                                      
   12513   xxx       localhost xxx        39  Query SELECT name FROM user WHERE no = '2488'                                                                                                    
   12511   xxx       localhost xxx        40  Query UPDATE `user` SET `exp` = exp+6, `vright` = vright+1, `correct` = correct+1 WHERE `name` = 'Amethys'                                       
   12465   xxx       localhost xxx        48  Query SELECT * FROM user WHERE name = 'pinoysamurai'                                                                                             
   12483   xxx       localhost xxx        48  Query SELECT * FROM user WHERE name = 'pinoysamurai'                                                                                             
   12501   xxx       localhost xxx        52  Query UPDATE `user` SET `exp` = exp+7, `vright` = vright+1, `correct` = correct+1 WHERE `name` = 'yuya_sama'                                     
   12422   xxx       localhost xxx        57  Query SELECT uo.name, ( SELECT COUNT(*) FROM user ui WHERE (ui.kright, ui.no) >= (uo.kright, uo.no) ) AS rank FROM user uo WHERE name = 0  

最底层的查询花了 100 多秒才能完成。而还没完成,后面的队列也卡住了。您可以在 mytop 输出中看到它。

这有什么问题吗? 我很郁闷...

我正在使用 itk mpm 这是我的 my.cnf 文件:(我有 512-1GB 的 RAM,

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
old_passwords=1
interactive_timeout=27
wait_timeout=10
connect_timeout=10
skip-locking
skip-innodb
skip-bdb
max_connections=77
table_cache=2M
thread_cache_size=2M
query_cache_type=1
query_cache_limit=1M
query_cache_size=64M
key_buffer_size=64M
read_rnd_buffer_size=2M
read_buffer_size=2M
sort_buffer_size=2M
join_buffer_size=2M
thread_cache_size=128
thread_concurrency=12
thread_stack =256K
tmp_table_size=32M

谢谢,

Recently, sometimes I cannot open my site.

I'm using VPS for hosting.

and when I do mytop

it shows me:

       User         Host/IP         DB      Time    Cmd Query or State                                                                                                                             
      --      ----         -------         --      ----    --- ----------                                                                                   
   12512   xxx       localhost xxx        39  Query SELECT * FROM user WHERE no = '12341'                                                                                                      
   12513   xxx       localhost xxx        39  Query SELECT name FROM user WHERE no = '2488'                                                                                                    
   12511   xxx       localhost xxx        40  Query UPDATE `user` SET `exp` = exp+6, `vright` = vright+1, `correct` = correct+1 WHERE `name` = 'Amethys'                                       
   12465   xxx       localhost xxx        48  Query SELECT * FROM user WHERE name = 'pinoysamurai'                                                                                             
   12483   xxx       localhost xxx        48  Query SELECT * FROM user WHERE name = 'pinoysamurai'                                                                                             
   12501   xxx       localhost xxx        52  Query UPDATE `user` SET `exp` = exp+7, `vright` = vright+1, `correct` = correct+1 WHERE `name` = 'yuya_sama'                                     
   12422   xxx       localhost xxx        57  Query SELECT uo.name, ( SELECT COUNT(*) FROM user ui WHERE (ui.kright, ui.no) >= (uo.kright, uo.no) ) AS rank FROM user uo WHERE name = 0  

the most bottom query took more than 100 seconds to complete. and before it is completed, the queue behind it got stuck as well. You can see it on the mytop output.

what is the problem of this?
I am so depressed...

I'm using itk mpm
and here is my my.cnf file: (I have 512-1GB of RAM

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
old_passwords=1
interactive_timeout=27
wait_timeout=10
connect_timeout=10
skip-locking
skip-innodb
skip-bdb
max_connections=77
table_cache=2M
thread_cache_size=2M
query_cache_type=1
query_cache_limit=1M
query_cache_size=64M
key_buffer_size=64M
read_rnd_buffer_size=2M
read_buffer_size=2M
sort_buffer_size=2M
join_buffer_size=2M
thread_cache_size=128
thread_concurrency=12
thread_stack =256K
tmp_table_size=32M

Thank You,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫九 2024-09-19 15:58:54

也许它有助于在 kright, no 上添加组合索引,以便连接更快?但我不确定 MySQL 是否会遵守这一点。

Maybe it helps adding a combined index on kright, no so the join is faster? But I am not sure if MySQL would honour that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文