웹프로그래밍 무작정따라하기/Database
[DB] MariaDB block 해제 방법 / 최대 접속 확인 및 늘리기
RIMD
2023. 8. 22. 16:02
connection locked 현상조치
위의 그림은
Remote서버에서 MysqlDB로 단순 커넥션 한 뒤 Close를 하게 되면 Mysql은 비정상적인 접속으로 판단하고
Remote서버의 IP를 블럭킹하게 된다.
이 때 Mysql에서는 비정삭적인 접속에 대한 요청수를 카운트하며 설정된 max_connect_error값에 의해 차단 되어
위와 같은 증상이 발생하게 된다.
조치 방법
그럴 경우, 아래와 같이 원격서버에서 MysqlDB에 접속 한 다음 connection상태를 확인한다.
// 현재 접속중인 커넥션 확인 하는 쿼리
MariaDB [mysql]> show status like 'threads_connected';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_connected | 2 |
+-------------------+-------+
1 row in set (0.001 sec)
// 현재 접속중인 커넥션 2
// 동시접속 설정을 확인하는 쿼리
// mysql은 기본 100
MariaDB [mysql]> show variables like '%max_connect%';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| extra_max_connections | 1 |
| max_connect_errors | 105 |
| max_connections | 151 |
+-----------------------+-------+
3 rows in set (0.001 sec)
max_connect_errors설정 확인 및 변경 방법.
// max_connect_errors카운트 확인
mysql [(none)] > select@@global.max_connect_errors;
+-----------------------------+
| @@global.max_connect_errors |
+-----------------------------+
| 10 |
+-----------------------------+
1 row in set (0.00 sec)
// max_connections 카운트 확인
mysql [(none)] > select@@global.max_connections;
// 에러 카운트 초기화
mysql [(none)] > flush hosts;
// max_connect_errors변경
mysql [(none)] > set global max_connect_errors=1000;
Query OK, 0 rows affected (0.00 sec)
// max_connections 변경
mysql [(none)] > set global max_connections=300;
// max_connect_errors카운트 설정되었는지 재확인
mysql [(none)] > select@@global.max_connect_errors;
+-----------------------------+
| @@global.max_connect_errors |
+-----------------------------+
| 1000 |
+-----------------------------+
1 row in set (0.00 sec)
max_connections, max_connect_errors값을 변경하면 되지만
flush hosts명령어를 실행하여 초기화 화면 정상적으로 접속이 된다.
* mysql을 재시작하지않아도 된다.