mysql连接超时的参数设置_MySQL
最近系统因为数据库连接超时的问题,出现了几次故障。排查了下my.cnf的配置问题,最后是代码设计有问题。正好就把所有的timeout参数都理一遍,首先数据库里查一下看有哪些超时:
mysql> show global variables like "%timeout%";
+-----------------------------+----------+
| Variable_name | Value |
+-----------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 120 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 3600 |
| wait_timeout | 28800 |
+-----------------------------+----------+
12 rows in set (0.00 sec)
我们来分析下各个参数的意义:
connect_timeout
手册描述:
The number of seconds that the mysqld server waits for a connect packet before responding with 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.
解释:在获取链接时,等待握手的超时时间,只在登录时有效,登录成功这个参数就不管事了。主要是为了防止网络不佳时应用重连导致连接数涨太快,一般默认即可。
delayed_insert_timeout
手册描述:
How many seconds an INSERT DELAYED handler thread should wait for INSERT statements before terminating.
解释:这是为MyISAM INSERT DELAY设计的超时参数,在INSERT DELAY中止前等待INSERT语句的时间。
innodb_lock_wait_timeout
手册描述:
The timeout in seconds an InnoDB transaction may wait for a row lock before giving up. The default value is 50 seconds. A transaction that tries to access a row that is locked by another InnoDB transaction will hang for at most this many seconds before issuing the following error:
1
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
When a lock wait timeout occurs, the current statement is not executed. The current transaction is not rolled back. (To have the entire transaction roll back, start the server with the –innodb_rollback_on_timeout option, available as of MySQL 5.1.15. See also Section 13.6.12, “InnoDB Error Handling”.)
innodb_lock_wait_timeout applies to InnoDB row locks only. A MySQL table lock does not happen inside InnoDB and this timeout does not apply to waits for table locks.
InnoDB does detect transaction deadlocks in its own lock table immediately and rolls back one transaction. The lock wait timeout value does not apply to such a wait.
For the built-in InnoDB, this variable can be set only at server startup. For InnoDB Plugin, it can be set at startup or changed at runtime, and has both global and session values.
解释:描述很长,简而言之,就是事务遇到锁等待时的Query超时时间。跟死锁不一样,InnoDB一旦检测到死锁立刻就会回滚代价小的那个事务,锁等待是没有死锁的情况下一个事务持有另一个事务需要的锁资源,被回滚的肯定是请求锁的那个Query。
innodb_rollback_on_timeout
手册描述:
In MySQL 5.1, InnoDB rolls back only the last statement on a transaction timeout by default. If –innodb_rollback_on_timeout is specified, a transaction timeout causes InnoDB to abort and roll back the entire transaction (the same behavior as in MySQL 4.1). This variable was added in MySQL 5.1.15.
解释:这个参数关闭或不存在的话遇到超时只回滚事务最后一个Query,打开的话事务遇到超时就回滚整个事务。
interactive_timeout/wait_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
解释:一个持续SLEEP状态的线程多久被关闭。线程每次被使用都会被唤醒为acrivity状态,执行完Query后成为interactive状态,重新开始计时。wait_timeout不同在于只作用于TCP/IP和Socket链接的线程,意义是一样的。一般设置是8小时,一般网站白天都有人访问,从夜里到早上一般都会超过8小时,所以再来访问就会这个问题。
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状态下的线程才有效的参数
slave_net_timeout
手册描述:
The number of seconds to wait for more data from the master before the slave considers the connection broken, aborts the read, and tries to reconnect. The first retry occurs immediately after the timeout. The interval between retries is controlled by the MASTER_CONNECT_RETRY option for the CHANGE MASTER TO statement or –master-connect-retry option, and the number of reconnection attempts is limited by the –master-retry-count option. The default is 3600 seconds (one hour).
解释:这是Slave判断主机是否挂掉的超时设置,在设定时间内依然没有获取到Master的回应就人为Master挂掉了

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

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

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

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

PHP5.4 버전의 새로운 기능: 호출 가능 유형 힌트 매개변수를 사용하여 호출 가능 함수 또는 메소드를 허용하는 방법 소개: PHP5.4 버전에는 매우 편리한 새 기능이 도입되었습니다. 호출 가능 유형 힌트 매개변수를 사용하여 호출 가능 함수 또는 메소드를 허용할 수 있습니다. 이 새로운 기능을 사용하면 함수와 메서드가 추가 확인 및 변환 없이 해당 호출 가능 매개변수를 직접 지정할 수 있습니다. 이 기사에서는 호출 가능 유형 힌트의 사용을 소개하고 몇 가지 코드 예제를 제공합니다.

제품 매개변수는 제품 속성의 의미를 나타냅니다. 예를 들어 의류 매개변수에는 브랜드, 소재, 모델, 크기, 스타일, 직물, 적용 그룹, 색상 등이 포함됩니다. 식품 매개변수에는 브랜드, 중량, 재료, 건강 허가 번호, 적용 그룹, 색상 등이 포함됩니다. 브랜드, 크기, 색상, 원산지, 적용 가능한 전압, 신호, 인터페이스 및 전원 등이 포함됩니다.

C++ 매개변수 유형 안전성 검사는 함수가 컴파일 시간 검사, 런타임 검사 및 정적 어설션을 통해 예상된 유형의 값만 허용하도록 보장하여 예기치 않은 동작 및 프로그램 충돌을 방지합니다. 컴파일 시간 유형 검사: 컴파일러가 유형 호환성을 검사합니다. 런타임 유형 검사: 동적_캐스트를 사용하여 유형 호환성을 확인하고 일치하는 항목이 없으면 예외를 발생시킵니다. 정적 어설션: 컴파일 타임에 유형 조건을 어설션합니다.

개발 과정에서 다음과 같은 오류 메시지가 나타날 수 있습니다: PHPWarning: in_array()expectsparameter. 이 오류 메시지는 in_array() 함수를 사용할 때 나타나는데, 이는 함수의 잘못된 매개변수 전달로 인해 발생할 수 있습니다. 이 오류 메시지에 대한 해결 방법을 살펴보겠습니다. 먼저 in_array() 함수의 역할을 명확히 해야 합니다. 즉, 배열에 값이 존재하는지 확인해야 합니다. 이 함수의 프로토타입은 다음과 같습니다: in_a

쌍곡선 함수는 원 대신 쌍곡선을 사용하여 정의되며 일반 삼각 함수와 동일합니다. 제공된 각도(라디안)에서 쌍곡사인 함수의 비율 매개변수를 반환합니다. 그러나 반대로 하십시오. 즉, 반대로 하십시오. 쌍곡선 사인으로부터 각도를 계산하려면 쌍곡선 역사인 연산과 같은 역쌍곡선 삼각법 연산이 필요합니다. 이 과정에서는 라디안 단위의 쌍곡선 사인 값을 사용하여 각도를 계산하기 위해 C++에서 쌍곡선 역사인(asinh) 함수를 사용하는 방법을 보여줍니다. 쌍곡선 아크사인 연산은 다음 공식 -$$\mathrm{sinh^{-1}x\:=\:In(x\:+\:\sqrt{x^2\:+\:1})}을 따릅니다. 여기서\:In\:은\:자연 로그\:(log_e\:k)

i9-12900H는 14코어 프로세서로, 사용된 아키텍처와 기술이 모두 새롭고, 전반적인 작업이 매우 뛰어나며, 특히 포괄적이며 사용자에게 뛰어난 경험을 제공할 수 있습니다. . i9-12900H 매개변수 평가 검토: 1. i9-12900H는 14코어 프로세서로, q1 아키텍처와 24576kb 프로세스 기술을 채택하고 20스레드로 업그레이드되었습니다. 2. 최대 CPU 주파수는 1.80!5.00ghz이며 주로 작업량에 따라 다릅니다. 3. 가격에 비해 가격 대비 성능이 매우 적합하며 정상적인 사용이 필요한 일부 파트너에게 매우 적합합니다. i9-12900H 매개변수 평가 및 성능 벤치마크

LLM(Large Language Model)은 강력한 성능을 갖고 있지만 매개변수의 수는 쉽게 수백억, 수천억에 달할 수 있고 컴퓨팅 장비와 메모리에 대한 수요도 일반 기업이 감당할 수 없을 만큼 크다. 양자화는 모델 가중치의 정확도(예: 32비트를 8비트로)를 줄여 추론 속도를 높이고 메모리 요구 사항을 줄이는 대신 일부 모델 성능을 희생하는 일반적인 압축 작업입니다. 그러나 1,000억 개 이상의 매개변수가 있는 LLM의 경우 기존 압축 방법으로는 모델의 정확성을 유지할 수 없으며 하드웨어에서 효율적으로 실행할 수도 없습니다. 최근 MIT와 NVIDIA의 연구원들은 범용 사후 훈련 양자화(GPQ)를 공동으로 제안했습니다.

GPT-4를 이길 수 있는 오픈소스 모델이 등장했습니다! 대형 모델 경기장의 최신 전투 보고서: 1040억 매개변수 오픈 소스 모델 CommandR+가 GPT-4-0314와 동점을 이루고 GPT-4-0613을 능가하여 6위로 올랐습니다. Image 이것은 또한 대형 모델 분야에서 GPT-4를 능가한 최초의 개방형 모델이기도 합니다. 대형 모델 경기장은 마스터 Karpathy가 신뢰하는 유일한 테스트 벤치마크 중 하나입니다. AI 유니콘 Cohere의 이미지 CommandR+. 이 대형 모델 스타트업의 공동 창업자이자 CEO는 바로 트랜스포머(일명 밀 수확자)의 최연소 작가인 에이든 고메즈다. 이 배틀 리포트가 나오자마자 또 다른 빅 모델 클럽들의 물결이 시작됐다.
