데이터 베이스 MySQL 튜토리얼 MySQL查询超时的设置方法

MySQL查询超时的设置方法

Jun 07, 2016 pm 03:15 PM
linux 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] 

MySQL查询超时的设置方法

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

뜨거운 기사 태그

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

DeepSeek 웹 버전 입구 DeepSeek 공식 웹 사이트 입구 DeepSeek 웹 버전 입구 DeepSeek 공식 웹 사이트 입구 Feb 19, 2025 pm 04:54 PM

DeepSeek 웹 버전 입구 DeepSeek 공식 웹 사이트 입구

Android TV Box, 비공식 Ubuntu 24.04 업그레이드 제공 Android TV Box, 비공식 Ubuntu 24.04 업그레이드 제공 Sep 05, 2024 am 06:33 AM

Android TV Box, 비공식 Ubuntu 24.04 업그레이드 제공

DeepSeek을 설치하는 방법 DeepSeek을 설치하는 방법 Feb 19, 2025 pm 05:48 PM

DeepSeek을 설치하는 방법

MySQL 8.4에서 mysql_native_password가 로드되지 않음 오류를 수정하는 방법 MySQL 8.4에서 mysql_native_password가 로드되지 않음 오류를 수정하는 방법 Dec 09, 2024 am 11:42 AM

MySQL 8.4에서 mysql_native_password가 로드되지 않음 오류를 수정하는 방법

BitPie Bitpie 지갑 앱 다운로드 주소 BitPie Bitpie 지갑 앱 다운로드 주소 Sep 10, 2024 pm 12:10 PM

BitPie Bitpie 지갑 앱 다운로드 주소

Bitget 공식 웹 사이트 설치 (2025 초보자 안내서) Bitget 공식 웹 사이트 설치 (2025 초보자 안내서) Feb 21, 2025 pm 08:42 PM

Bitget 공식 웹 사이트 설치 (2025 초보자 안내서)

Zabbix 3.4 소스 코드 컴파일 설치 Zabbix 3.4 소스 코드 컴파일 설치 Sep 04, 2024 am 07:32 AM

Zabbix 3.4 소스 코드 컴파일 설치

자세한 설명: 쉘 스크립트 변수 판단 매개변수 명령 자세한 설명: 쉘 스크립트 변수 판단 매개변수 명령 Sep 02, 2024 pm 03:25 PM

자세한 설명: 쉘 스크립트 변수 판단 매개변수 명령

See all articles