MySQL查询超时问题的解决

数据库 MySQL
MySQL在查询时会遇到各种各样的问题,查询超时就是一个典型的问题,下文就教您一个解决MySQL查询超时问题的方法,供您参考。

MySQL查询超时问题是什么原因呢?应该如何解决呢?下面就为您详细介绍MySQL查询超时问题的解决方法,希望可以帮助到您。

  1. mysql>show variables like '%timeout';   
  2.  

打印结果如下:

  1. +----------------------------+-------+   
  2. | Variable_name | Value |   
  3. +----------------------------+-------+   
  4. | connect_timeout | 5 |   
  5. | delayed_insert_timeout | 300 |   
  6. | interactive_timeout | 28800 |   
  7. | net_read_timeout | 30 |   
  8. | net_write_timeout | 60 |   
  9. | slave_net_timeout | 3600 |   
  10. | wait_timeout | 28800 |   
  11. +----------------------------+-------+   
  12.  

interactive_timeout 需在mysql_connect()设置CLIENT_INTERACTIVE选项后起作用,并被赋值为wait_timeout;

mysql>set wait_timeout = 10; 对当前交互链接有效;
mysql>set interactive_timeout = 10; 对后续起的交互链接有效;

该超时时间单位是秒,从变量从上次SQL执行后算起;当前空闲若超过该时间,则也会被强制断开。

interactive_timeout(常用)

The number of seconds the server waits for activity on an interactive connection before closing it. An interactive client is defined as a client that uses the CLIENT_INTERACTIVE option to mysql_real_connect(). See also wait_timeout.

译解:客户端和服务器交互的空闲超时时间。该系统变量仅当客户端连接服务器时设置了“MYSQL_CLIENT_INTERACTIVE”标志才生效,例如:

  1. //启用MYSQL_CLIENT_INTERACTIVE模式,连接数据库服务器  
  2.  
  3. $link = mysql_connect($host, $user, $pwd, false, MYSQL_CLIENT_INTERACTIVE);  
  4.  

 

 

 

【编辑推荐】

教您如何调整MySQL查询缓冲

MySQL查询优化器的工作原理

深度解析MySQL查询缓存机制

常用MySQL命令行工具介绍

MySQL无重复查询的实现

责任编辑:段燃 来源: 互联网
相关推荐

2010-10-14 09:15:20

MySQL查询

2020-04-23 11:43:55

MySQL数据库SQL

2009-03-24 10:45:39

MySQL5连接超时数据库

2015-03-09 15:41:08

MongoDB查询超时异常Socket Time

2009-06-03 15:50:51

eclipse中启动超eclipsetomcat

2011-03-22 16:09:33

MySQL 5.0.1乱码

2021-06-08 08:38:36

MySQL数据库死锁问题

2010-11-23 15:20:47

MySQL多联表查询

2010-10-13 17:22:12

MySQL查询乱码

2010-11-25 11:31:52

MySQL查询

2010-11-25 15:57:49

mysql查询语句

2010-05-12 09:08:49

Mysql中文

2010-05-25 11:24:34

MySQL 乱码

2013-07-04 10:55:20

2010-05-25 15:32:39

MySQL 中文问题

2010-05-17 09:49:46

MySQL中文问题

2011-04-07 14:29:56

2021-10-14 10:53:20

数据库查询超时

2009-12-17 10:09:02

ssh超时断开

2010-11-25 16:09:58

mysql查询大小写
点赞
收藏

51CTO技术栈公众号