99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

MySQL怎么設(shè)置超時 mysql連接超時時間查詢

C#連接mysql數(shù)據(jù)庫,怎么設(shè)置超時時間

MySQL查詢超時的設(shè)置方法

成都創(chuàng)新互聯(lián)是專業(yè)的漯河網(wǎng)站建設(shè)公司,漯河接單;提供網(wǎng)站制作、成都網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行漯河網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!

為了優(yōu)化OceanBase的query timeout設(shè)置方式,特調(diào)研MySQL關(guān)于timeout的處理,記錄如下。

[plain]

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)

重點解釋其中幾個參數(shù):

connect_timeout:

The number of seconds that the mysqld server waits for a connect packet before respondingwith Bad handshake. The default value is 10 seconds as of MySQL 5.1.23 and 5 seconds before that. Increasing the connect_timeout value might help if clients frequently encounter errors of the form Lost connection to MySQL server at ‘XXX’, system error: errno.

解釋:在獲取鏈接時,等待握手的超時時間,只在登錄時有效,登錄成功這個參數(shù)就不管事了。主要是為了防止網(wǎng)絡(luò)不佳時應(yīng)用重連導(dǎo)致連接數(shù)漲太快,一般默認(rèn)即可。

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 alsowait_timeout.

解釋:一個持續(xù)SLEEP狀態(tài)的線程多久被關(guān)閉。線程每次被使用都會被喚醒為acrivity狀態(tài),執(zhí)行完Query后成為interactive狀態(tài),重新開始計時。wait_timeout不同在于只作用于TCP/IP和Socket鏈接的線程,意義是一樣的。

MySQL可以配置連接的超時時間,這個時間如果做得太長,甚至到了10min,那么很可能發(fā)生這種情況,3000個鏈接都被占滿而且sleep在哪,新鏈接進不來,導(dǎo)致無法正常服務(wù)。因此這個配置盡量配置一個符合邏輯的值,60s或者120s等等。

說人話:

命令行下面敲一個命令后,直至下一個命令到來之前的時間間隔為interactive_time,如果這個時間間隔超過了interactive_timeout,則連接會被自動斷開,下一個命令失敗。不過一般的mysql客戶端都有自動重連機制,下一個命令會在重連后執(zhí)行。

[sql]

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)

=====

[sql]

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)

wait_timeout:

The number of seconds the server waits for activity on a noninteractive connection (連接上沒有活動命令,可能是客戶端喝咖啡去了。)before closing it. 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.

On thread startup, the session wait_timeout value is initialized from the global wait_timeout value or from the global interactive_timeout value, depending on the type of client

這里順帶解釋一下什么是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.

解釋:這個參數(shù)只對TCP/IP鏈接有效,分別是數(shù)據(jù)庫等待接收客戶端發(fā)送網(wǎng)絡(luò)包和發(fā)送網(wǎng)絡(luò)包給客戶端的超時時間,這是在Activity狀態(tài)下的線程才有效的參數(shù)

JDBC setQueryTimeout函數(shù):

為了避免查詢出現(xiàn)死循環(huán),或時間過長等現(xiàn)象,而導(dǎo)致線程阻塞,在獲得Statement的實例后,stmt.setQueryTimeout(10); 避免因為查詢導(dǎo)致程序出現(xiàn)線程阻塞。

但昨天發(fā)現(xiàn)程序出現(xiàn)了,“ORA-01013: 用戶請求取消當(dāng)前的操作”的異常。手工執(zhí)行出錯SQL語句發(fā)現(xiàn),這個語句耗時20多秒。因為setQueryTimeout(10),所以還沒有執(zhí)行完查詢語句就拋出異常了。使用setQueryTimeout(10)時一定要把時間設(shè)置的長一些,如60秒以上。只要不導(dǎo)致線程長期阻塞,就可以。太短了容易拋出,“ORA-01013: 用戶請求取消當(dāng)前的操作”的異常

JDBC實現(xiàn)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());

}

}

}

如何配置MySQL數(shù)據(jù)庫超時設(shè)置

大規(guī)模多線程操作事務(wù)的時候,有時候打開一個鏈接,會進行等待,這時候如果數(shù)據(jù)庫的超時時間設(shè)置的過短,就可能會出現(xiàn),數(shù)據(jù)鏈接自動被釋放,當(dāng)然設(shè)置過大也不好,慢SQL或其他因素引起的鏈接過長,導(dǎo)致整個系統(tǒng)被拖慢,甚至掛掉。SO,適當(dāng)?shù)脑O(shè)置超時時間。設(shè)置方法:

SHOW GLOBAL VARIABLES LIKE '%timeout%'

SET GLOBAL wait_timeout=10000

網(wǎng)頁鏈接

mysql怎么設(shè)置超時時間

MYSQL_OPT_READ_TIMEOUT 是 MySQL c api 客戶端中用來設(shè)置讀取超時時間的參數(shù)。在 MySQL 的官方文檔中,該參數(shù)的描述是這樣的:

MYSQL_OPT_READ_TIMEOUT (argument type: unsigned int *)The timeout in seconds for each attempt to read from the server. There are retries if necessary, so the total effective timeout value is three times the option value. You can set the value so that a lost connection can be detected earlier than the TCP/IPClose_Wait_Timeout value of 10 minutes.

也就是說在需要的時候,實際的超時時間會是設(shè)定值的 3 倍。但是實際測試后發(fā)現(xiàn)實際的超時時間和設(shè)置的超時時間一致。

而具體什么時候發(fā)生三倍超時,在文檔中沒有找到。所以對 MySQL 5.7.20 的源碼進行了一些分析。

使用 GDB 調(diào)試代碼找了實際與 mysql server 通信的代碼,如下:

請點擊輸入圖片描述

其中 vio_read() 函數(shù)中,使用 recv 和 poll 來讀取報文和做讀取超時。net_should_retry() 函數(shù)只有在發(fā)生 EINTR 時才會返回 true。從這段代碼來看是符合測試結(jié)果的,并沒有對讀取進行三次重試。只有在讀取操作被系統(tǒng)中斷打斷時才會重試,但是這個重試并沒有次數(shù)限制。

從上面代碼的分析可以看出,代碼的邏輯和文檔的描述不符。于是在一頓搜索后,找到了一個 MySQL 的 BUG(Bug #31163)。該 BUG 報告了在?MySQL?5.0 中,MySQL c api 讀取的實際超時時間是設(shè)置的三倍,與現(xiàn)有文檔描述相符。于是對 MySQL 5.0.96 的代碼又進行分析。

同樣使用 GDB 找到了通信部分的代碼。這次找到了重試三次的代碼,如下:

請點擊輸入圖片描述

這個版本的 MySQL api 的讀寫超時是直接使用的 setsockopt 設(shè)置的。第一次循環(huán),在 A 點發(fā)生了第一次超時(雖然注釋寫的非阻塞,但是客戶端的連接始終是阻塞模式的)。然后在 B 點將該 socket 設(shè)置為阻塞模式,C 點這里重置 retry 次數(shù)。由于設(shè)置了 alarm 第二次以后的循環(huán)會直接進入 D 點的這個分支,并且判斷循環(huán)次數(shù)。作為客戶端時net-retry_count 始終是 1,所以重試了兩次,共計進行了 3 次 vioread 后從 E 點退出函數(shù)。

由上面的分析可知,MySQL 文檔對于該參數(shù)的描述已經(jīng)過時,現(xiàn)在的 MYSQL_OPT_READ_TIMEOUT 并不會出現(xiàn)三倍超時的問題。而 Bug #31163 中的處理結(jié)果也是將文檔中該參數(shù)的描述更新為實際讀取超時時間是設(shè)定時間的三倍。也許是 MySQL 的維護者們在后續(xù)版本更新時忘記更新文檔吧。

mysql可以自定義超時嗎

connect_timeout:連接響應(yīng)超時時間。服務(wù)器端在這個時間內(nèi)如未連接成功,則會返回連接失敗。

wait_timeout:連接空閑超時時間。與服務(wù)器端無交互狀態(tài)的連接,直到被服務(wù)器端強制關(guān)閉而等待的時間。可以認(rèn)為是服務(wù)器端連接空閑的時間,空閑超過這個時間將自動關(guān)閉。

interactive_timeout :連接空閑超時時間。與服務(wù)器端無交互狀態(tài)的連接,直到被服務(wù)器端強制關(guān)閉而等待的時間。

interactive_timeout和wait_timeoutu意義雖然相同,但是有使用對象有本質(zhì)的區(qū)別。interactive_timeout針對交互式連接(比如通過mysql客戶端連接數(shù)據(jù)庫),wait_timeout針對非交互式連接(比如一般在PHP中使用PDO連接數(shù)據(jù)庫,當(dāng)然你可以設(shè)置CLIENT_INTERACTIVE選項來改變)。所謂的交互式連接,即在mysql_real_connect()函數(shù)中使用了CLIENT_INTERACTIVE選項。

net_read_timeout :數(shù)據(jù)讀取超時時間。在終止讀之前,從一個連接獲得數(shù)據(jù)而等待的時間秒數(shù);當(dāng)服務(wù)正在從客戶端讀取數(shù)據(jù)時,net_read_timeout控制何時超時。即客戶端執(zhí)行數(shù)據(jù)讀取,等待多少秒仍未執(zhí)行成功時自動斷開連接。

net_write_timeout:數(shù)據(jù)庫寫超時時間。和net_read_timeout意義類似,在終止寫之前,等待多少秒把block寫到連接;當(dāng)服務(wù)正在寫數(shù)據(jù)到客戶端時,net_write_timeout控制何時超時。

slave-net-timeout:從庫延后同步的時間,當(dāng)slave認(rèn)為連接master的連接有問題時,就等待N秒,然后斷開連接,重新連接master

slave-net-timeout在主從同步時從庫上起作用;connect_timeout:在獲取連接階段起作用;interactive_timeout和wait_timeout:在連接空閑階段起作用;net_read_timeout和net_write_timeout:則是在連接執(zhí)行時起作用。

怎樣配置MySQL數(shù)據(jù)庫超時設(shè)置

mysql命令

查看mysql server超時時間:

msyql show global variables like '%timeout%';

設(shè)置mysql server超時時間(以秒為單位):

msyql set global wait_timeout=10;

msyql set global interactive_timeout=10;

MySql執(zhí)行超時怎么設(shè)置

?php

$db-query("SET interactive_timeout = 3600;");

$db-query("SET wait_timeout = 3600;");

?

新聞名稱:MySQL怎么設(shè)置超時 mysql連接超時時間查詢
當(dāng)前URL:http://www.yijiale78.com/article6/dodshig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)外貿(mào)網(wǎng)站建設(shè)營銷型網(wǎng)站建設(shè)網(wǎng)站改版網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司