“잠금 대기 시간 초과를 초과했습니다. '고착 된'MySQL 테이블에 대해 트랜잭션을 다시 시작 하시겠습니까?
스크립트에서 다음과 같은 쿼리를 로컬 데이터베이스에 보냈습니다.
update some_table set some_column = some_value
where 부분을 추가하는 것을 잊었으므로 동일한 열이 테이블의 모든 행에 대해 동일한 값으로 설정되었으며 수천 번 수행되었으며 열이 색인화되었으므로 해당 색인이 너무 많이 업데이트되었습니다. .
시간이 너무 오래 걸리기 때문에 스크립트가 잘못되었습니다. 그 이후로 컴퓨터를 재부팅했지만 간단한 쿼리를 실행하는 데 시간이 오래 걸리고 관련 인덱스를 삭제하려고하면이 메시지와 함께 실패하기 때문에 테이블에 문제가 발생했습니다.
Lock wait timeout exceeded; try restarting transaction
이것은 innodb 테이블이므로 트랜잭션이 내재되어있을 수 있습니다. 이 테이블을 수정하고 걸린 트랜잭션을 어떻게 제거 할 수 있습니까?
비슷한 문제가 있었고 실행중인 스레드를 확인하여 해결했습니다. 실행중인 스레드를 보려면 mysql 명령 행 인터페이스에서 다음 명령을 사용하십시오.
SHOW PROCESSLIST;
mysql 명령 행 인터페이스에 액세스 할 수없는 경우 phpMyAdmin에서 보낼 수도 있습니다.
그러면 해당 id와 실행 시간이있는 스레드 목록이 표시되므로 실행하는 데 너무 많은 스레드를 종료 할 수 있습니다. phpMyAdmin에는 KILL을 사용하여 스레드를 중지하는 버튼이 있습니다. 명령 행 인터페이스를 사용하는 경우 다음 예제와 같이 KILL 명령과 스레드 ID를 사용하십시오.
KILL 115;
해당 스레드에 대한 연결이 종료됩니다.
당신은 현재 실행중인 거래를 확인할 수 있습니다
SELECT * FROM `information_schema`.`innodb_trx` ORDER BY `trx_started`
거래는 목록에서 가장 오래된 거래이므로 첫 번째 거래 중 하나 여야합니다. 이제 값을 가져 trx_mysql_thread_id
와서 다음 KILL
명령을 보내십시오 .
KILL 1234;
어떤 거래인지 확실하지 않은 경우 첫 번째 쿼리를 자주 반복하고 어떤 거래가 지속되는지 확인하십시오.
데이터베이스 크기가 커지고 많은 트랜잭션을 수행 할 때 이런 일이 시작되었습니다.
진실은 아마도 쿼리 또는 DB를 최적화 할 수있는 방법이 있지만 해결을 위해이 두 쿼리를 시도하십시오.
이것을 실행하십시오 :
SET GLOBAL innodb_lock_wait_timeout = 5000;
그리고 이것은 :
SET innodb_lock_wait_timeout = 5000;
잠금에 대한 InnoDB 상태 확인
SHOW ENGINE InnoDB STATUS;
MySQL 오픈 테이블 확인
SHOW OPEN TABLES WHERE In_use > 0;
보류중인 InnoDB 트랜잭션 확인
SELECT * FROM `information_schema`.`innodb_trx` ORDER BY `trx_started`;
잠금 종속성 확인-무엇을 차단
SELECT * FROM `information_schema`.`innodb_locks`;
위의 결과를 조사한 후 무엇을 잠그고 있는지 확인할 수 있습니다.
문제의 근본 원인이 코드에있을 수도 있습니다. Hibernate와 같은 JPA를 사용하는 경우 특히 주석에 대한 관련 함수를 확인하십시오.
예를 들어 here 에 설명 된대로 다음 주석을 잘못 사용하면 데이터베이스가 잠길 수 있습니다.
@Transactional(propagation = Propagation.REQUIRES_NEW)
MySQL을 다시 시작하면 제대로 작동합니다.
그러나 이러한 쿼리가 중단되면 어딘가에 문제가 있음을 명심하십시오.
- 귀하의 질문에 (잘못 배치 된 문자, 직교 곱, ...)
- 편집 할 매우 많은 레코드
- 복잡한 조인 또는 테스트 (MD5, 하위 문자열
LIKE %...%
등) - 데이터 구조 문제
- 외래 키 모델 (체인 / 루프 잠금)
- 잘못 색인 된 데이터
@syedrakib가 말했듯이 작동하지만 이것은 생산을위한 오래 살지 않는 솔루션입니다.
주의 : 다시 시작하면 일관성이없는 데이터에 영향을 줄 수 있습니다.
Also, you can check how MySQL handles your query with the EXPLAIN keyword and see if something is possible there to speed up the query (indexes, complex tests,...).
When you establish a connection for a transaction, you acquire a lock before performing the transaction. If not able to acquire the lock, then you try for sometime. If lock is still not obtainable, then lock wait time exceeded error is thrown. Why you will not able to acquire a lock is that you are not closing the connection. So, when you are trying to get a lock second time, you will not be able to acquire the lock as your previous connection is still unclosed and holding the lock.
Solution: close the connection or setAutoCommit(true) [according to your design] to release the lock.
Goto processes in mysql.
So can see there is task still working.
Kill the the particular process or wait until process complete.
I had this problem when trying to delete a certain group of records (using MS Access 2007 with an ODBC connection to MySQL on a web server). Typically I would delete certain records from MySQL then replace with updated records (cascade delete several related records, this streamlines deleting all related records for a single record deletion).
I tried to run through the operations available in phpMyAdmin for the table (optimize,flush, etc), but I was getting a need permission to RELOAD error when I tried to flush. Since my database is on a web server, I couldn't restart the database. Restoring from a backup was not an option.
I tried running delete query for this group of records on the cPanel mySQL access on the web. Got same error message.
My solution: I used Sun's (Oracle's) free MySQL Query Browser (that I previously installed on my computer) and ran the delete query there. It worked right away, Problem solved. I was then able to once again perform the function using the Access script using the ODBC Access to MySQL connection.
I ran into the same problem with an "update"-statement. My solution was simply to run through the operations available in phpMyAdmin for the table. I optimized, flushed and defragmented the table (not in that order). No need to drop the table and restore it from backup for me. :)
I had the same issue. I think it was a deadlock issue with SQL. You can just force close the SQL process from Task Manager. If that didn't fix it, just restart your computer. You don't need to drop the table and reload the data.
Fixed it, Make sure you doesn't have mismatched data type insert in query. I had an issue where i was trying "user browser agent data" in "VARCHAR(255)" and having issue with this lock however when I changed it to "TEXT(255)" it fixed it. So most likely it is mis match of data type
I solved the problem by dropping the table and restoring it from backup.
'Programing' 카테고리의 다른 글
R 프로세스가 사용할 수있는 메모리를 늘리거나 줄입니다. (0) | 2020.07.22 |
---|---|
Flex / Lex와 Yacc / Bison의 차이점은 무엇입니까? (0) | 2020.07.22 |
const는 C ++ 11에서 스레드 안전을 의미합니까? (0) | 2020.07.22 |
Go에서 슬라이스를 어떻게 지우나요? (0) | 2020.07.21 |
html 루비 코드 주위에 link_to를 어떻게 래핑합니까? (0) | 2020.07.21 |