SQL查询超时的设置方法(关于timeout的处理)
2022-11-12 09:29:01
内容摘要
这篇文章主要为大家详细介绍了SQL查询超时的设置方法(关于timeout的处理),具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!为了优化OceanBa
文章正文
这篇文章主要为大家详细介绍了SQL查询超时的设置方法(关于timeout的处理),具有一定的参考价值,可以用来参考一下。
对此感兴趣的朋友,看看idc笔记做的技术笔记!
为了优化OceanBase的query timeout设置方式,特调研MySQL关于timeout的处理,记录如下。代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <code> mysql> show variables like '%time%' ; +----------------------------+-------------------+ | Variable_name | Value | +----------------------------+-------------------+ | connect_timeout | 10 | | datetime_format | %Y-%m-%d %H:%i:%s | | delayed_insert_timeout | 300 | | flush_time | 1800 | | innodb_lock_wait_timeout | 50 | | innodb_old_blocks_time | 0 | | innodb_rollback_on_timeout | OFF | | interactive_timeout | 28800 | | lc_time_names | en_US | | lock_wait_timeout | 31536000 | | long_query_time | 10.000000 | | net_read_timeout | 30 | | net_write_timeout | 60 | | slave_net_timeout | 3600 | | slow_launch_time | 2 | | system_time_zone | | | time_format | %H:%i:%s | | time_zone | SYSTEM | | timed_mutexes | OFF | | timestamp | 1366027807 | | wait_timeout | 28800 | +----------------------------+-------------------+ 21 rows in set, 1 warning (0.00 sec) </code> |
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 | <code> mysql> set interactive_timeout = 1; Query OK, 0 rows affected (0.00 sec) mysql> show session variables like '%timeout%' ; +----------------------------+----------+ | Variable_name | Value | +----------------------------+----------+ | connect_timeout | 10 | | interactive_timeout | 1 | | wait_timeout | 28800 | +----------------------------+----------+ 10 rows in set (0.00 sec) </code> |
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <code> mysql> set wait_timeout = 1; Query OK, 0 rows affected (0.00 sec) 【去泡杯茶,等会儿】 mysql> show session variables like '%timeout%' ; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 7 Current database: *** NONE *** +----------------------------+----------+ | Variable_name | Value | +----------------------------+----------+ | connect_timeout | 10 | | interactive_timeout | 28800 | | wait_timeout | 28800 | +----------------------------+----------+ 10 rows in set (0.01 sec) </code> |
代码如下:
1 2 3 | <code> c:\mysql\bin\mysql -u admin -p myDatabase -e 'SELECT * FROM employee' </code> |
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <code> class IfxCancelQueryImpl extends TimerTask implements IfmxCancelQuery { IfxStatement stmt; Timer t = null; public void startCancel(IfxStatement paramIfxStatement, int paramInt) throws Exception { this.stmt = paramIfxStatement; this.t = new Timer(true); this.t.schedule(this, paramInt * 1000); } public void run() { try { this.stmt.cancel(); this.t.cancel(); } catch (SQLException localSQLException) { this.t.cancel(); throw new Error(localSQLException.getErrorCode() + ":" + localSQLException.getMessage()); } } } </code> |
注:关于SQL查询超时的设置方法(关于timeout的处理)的内容就先介绍到这里,更多相关文章的可以留意
代码注释