MySQL, 커넥션 정보 확인 / 설정 / 삭제
글. 수알치 오상문
1. MySQL 최대 커넥션 개수 확인
show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 151 |
+-----------------+-------+
1 row in set, 1 warning (0.02 sec)
현재 최대 커넥션 개수는 151이다.
2. MySQL 커넥션 수 확인
show status where `variable_name` = 'Threads_connected';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_connected | 65 |
+-------------------+-------+
1 row in set (0.01 sec)
현재 커넥션 수는 65이다.
3. MySQL 최대 커넥션 수 설정 (예; 256)
set global max_connections=256;
Query OK, 0 rows affected (0.00 sec)
변경되었는지 확인해 보자.
show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 256 |
+-----------------+-------+
1 row in set, 1 warning (0.01 sec)
최대 커넥션 수가 256개로 변경되었음을 확인했다.
4. 클라이언트에서도 최대 커넥션 제한을 확인하고 변경합니다.
사용하는 프레임워크나 설정에 따라 다르니 따로 확인하기 바랍니다.
5. 현재 커넥션 프로세스 정보를 살펴보자.
show processlist;
+------+------+-----------------+-------+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+------+------+-----------------+-------+---------+------+----------+------------------+
| 1971 | root | localhost:60762 | world | Sleep | 3789 | | NULL |
| 1972 | root | localhost:60763 | world | Sleep | 3789 | | NULL |
| 1973 | root | localhost:60764 | world | Sleep | 3794 | | NULL |
| 1974 | root | localhost:60765 | world | Sleep | 3793 | | NULL |
| 1975 | root | localhost:60766 | world | Sleep | 3793 | | NULL |
...
| 2033 | root | localhost:60880 | world | Sleep | 3539 | | NULL |
| 2034 | root | localhost:60881 | world | Sleep | 3539 | | NULL |
| 2035 | root | localhost:61081 | NULL | Query | 0 | starting | show processlist |
+------+------+-----------------+-------+---------+------+----------+------------------+
65 rows in set (0.01 sec)
테스트 중에 종료되지 않고 비정상적으로 살아있는 커넥션 프로세스들이다.
(커넥션 프로세스는 타임아웃에 걸리면 제거되지만, 불필요한 것은 제거하는 것이 좋다.)
6. 커넥션 설정 정보 확인하기
show status like '%connect%';
+-----------------------------------------------+---------------------+
| Variable_name | Value |
+-----------------------------------------------+---------------------+
| Aborted_connects | 4 |
| Connection_errors_accept | 0 |
| Connection_errors_internal | 0 |
| Connection_errors_max_connections | 0 |
| Connection_errors_peer_address | 0 |
| Connection_errors_select | 0 |
| Connection_errors_tcpwrap | 0 |
| Connections | 2036 |
| Locked_connects | 0 |
| Max_used_connections | 65 |
| Max_used_connections_time | 2022-06-25 12:32:05 |
| Performance_schema_session_connect_attrs_lost | 0 |
| Ssl_client_connects | 0 |
| Ssl_connect_renegotiates | 0 |
| Ssl_finished_connects | 0 |
| Threads_connected | 65 |
+-----------------------------------------------+---------------------+
16 rows in set (0.00 sec)
여기에서 살펴볼 항목은 다음과 같다.
Aborted_connections : 연결에 실패한 개수
connections : 연결 시도된 전체 개수
Max_used_connections : 동시에 접속한 최대 개수
Threads_connected : 현재 연결된 개수
DBMS 성능 향상 튜닝 시 참고할 값들이다.
[참고] https://jiku90.tistory.com/14
Database(MYSQL)의 Connection Pool 및 튜닝
Connection Pool이란? 사용자의 요청에 따라 Connection을 생성하다 보면 많은 수의 연결이 발생했을 때 서버에 과부하가 걸리게 된다. 이러한 상황을 방지하기 위해 미리 일정수의 Connection을 만들어 Poo
jiku90.tistory.com
[참고] https://yhjin.tistory.com/m/92
Mysql Connection에 대하여
Mysql은 기본적으로 SQL Server와 다르게 Connection Pooling을 자체적으로 제공하지 않는다. 이는 연결 Driver가 SQL Server는 전용 Driver를 사용하기 때문에 그렇지만 Mysql의 첫 시작은 Open Source 진영이었..
yhjin.tistory.com
7. 타임아웃 정보 살펴보기
show variables like '%timeout%';
+-----------------------------+----------+
| Variable_name | Value |
+-----------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| have_statement_timeout | YES |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 50 |
| 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 | 60 |
| wait_timeout | 28800 |
+-----------------------------+----------+
13 rows in set, 1 warning (0.00 sec)
interactive_timeout : 프롬프트나 터미널 모드 연결 시 대기 시간
wait_timeout : 클라이언트 연결 시 최대 대기 시간
timeout 시간은 새로운 쿼리가 진행되면 다시 0부터 시작하고 제한 시간이 넘어가면 연결이 끊긴다.
8. 타임아웃 값 변경하기
set global interactive_timeout = 7200; <-- 60*60*2 = 2시간
set global wait_timeout = 7200;
이 변경은 디비 서버를 재시작할 때 적용된다. 현재 커넥션에는 영향을 주지 않는다.
[참고] MySQL 환경변수 파일에서 변경하는 방법
/etc/mysql/mariadb.conf.d/50-server.cnf 파일에서 아래 사항을 변경한다.
wait_timeout = 180 <
interactive_timeout = 180 <
9. 커넥션 삭제
1) MySQL 워크벤치(Workbench) 프로그램을 실행하고 MySQL 서버에 접속한다.
2) Server > Client Connections 메뉴에 접속한다.
3) 커넥션 목록에서 불필요한 커넥션을 선택(하나 또는 여러 개)하고 우클릭한다.
4) Kill Connection(s) 메뉴를 선택하면 커넥션이 삭제된다.
'DBMS,데이터베이스' 카테고리의 다른 글
MongoDB 관리자 권한 계정 생성/삭제 (0) | 2022.06.25 |
---|---|
MongoDB 레퍼런스 사이트 (0) | 2022.06.25 |
MySQL Timeout 설정 (0) | 2022.06.24 |
Mongo DB의 한글 Column 값 가져오기 (0) | 2022.06.23 |
MySQL 테이블, 컬럼에 한글/특수문자 있는 경우 접근하기 (0) | 2022.06.23 |