c mysql 查询超时设置_MySQL查询超时的设置方法
歡迎進入Linux社區論壇,與200萬技術人員互動交流 >>進入 這里順帶解釋一下什么是non-interactive connection Non-Interactive Commands Just do a quick look up on a table without logging into the client, running the query then logging back out aga
歡迎進入Linux社區論壇,與200萬技術人員互動交流 >>進入
這里順帶解釋一下什么是non-interactive connection
> Non-Interactive Commands
Just do a quick look up on a table without logging into the client, running the query then logging back out again.
You can instead just type one line using the ' -e ' flag.
[sql]
c:\mysql\bin\mysql -u admin -p myDatabase -e 'SELECT * FROM employee'
net_read_timeout / net_write_timeout
The number of seconds to wait for more data from a connection before aborting the read. Before MySQL 5.1.41, this timeout applies only to TCP/IP connections, not to connections made through Unix socket files, named pipes, or shared memory. When the server is reading from the client, net_read_timeout is the timeout value controlling when to abort. When the server is writing to the client, net_write_timeout is the timeout value controlling when to abort. See also slave_net_timeout.
On Linux, the NO_ALarm build flag affects timeout behavior as indicated in the description of the net_retry_count system variable.
解釋:這個參數只對TCP/IP鏈接有效,分別是數據庫等待接收客戶端發送網絡包和發送網絡包給客戶端的超時時間,這是在Activity狀態下的線程才有效的參數
JDBC setQueryTimeout函數:
為了避免查詢出現死循環,或時間過長等現象,而導致線程阻塞,在獲得Statement的實例后,stmt.setQueryTimeout(10); 避免因為查詢導致程序出現線程阻塞。
但昨天發現程序出現了,“ORA-01013: 用戶請求取消當前的操作”的異常。手工執行出錯SQL語句發現,這個語句耗時20多秒。因為setQueryTimeout(10),所以還沒有執行完查詢語句就拋出異常了。使用setQueryTimeout(10)時一定要把時間設置的長一些,如60秒以上。只要不導致線程長期阻塞,就可以。太短了容易拋出,“ORA-01013: 用戶請求取消當前的操作”的異常
JDBC實現setQueryTimeout的原理:
[java]
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());
}
}
}
可見,query timeout是通過客戶端解決方案來做的,服務器端無需知曉。通過一個timer線程來監控執行時間,如果執行時間超時,則會schedule run()函數。
[1] [2]
本文原創發布php中文網,轉載請注明出處,感謝您的尊重!
總結
以上是生活随笔為你收集整理的c mysql 查询超时设置_MySQL查询超时的设置方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python闪光培训班 费用-Pytho
- 下一篇: python os.environ wi