본문 바로가기
Database/Mysql

mysql/mariadb Aborted connection 에러

by 화곡공룡 2020. 12. 14.
반응형

mysql 서버를 운영하면서 에러로그 파일을 보니 정기적으로 아래와 같은 에러가 발생하고 있었다.

Aborted connection[Note] Aborted connection 72 to db: 'job' user: 'user' host: 'localhost' (Got an error reading communication packets)

에러 로그가 쌓이는 경로는 아래와 같이 확인할 수 있다.

mysql> show variables like 'log_error';
+---------------+---------------------+
| Variable_name | Value               |
+---------------+---------------------+
| log_error     | /var/log/mysqld.log |
+---------------+---------------------+
1 row in set (0.00 sec)

mysql>

 

에러가 발생하는 원인을 찾아보니 crontab 스케줄에 의해 돌아가는 Python프로그램에서 비정상적인 종료로 의해

발생하는 원인인것을 확인하였다.

 

아래와 같이 DB close가 없을 경우 발생하는 에러이다.

소스 샘플

import pymysql
import sys

def test_sel(col1, col2):
    conn = pymysql.connect(host="localhost", port=3306, user="root", passwd="testtest", db="test")
    try:
        cur = conn.cursor()
        sql=('select "{0}", "{1}"').format(col1, col2)
        print("excute sql :", sql)
        cur.execute(sql)
        result=cur.fetchall()
    except Exception as e:
        print(title,":",job, " : Exception occured:{}".format(e))
    finally:
        return result



>>> test_sel('a','b')
('excute sql :', 'select "a", "b"')
(('a', 'b'),)
>>>


-- mysql 에러 발생
2020-12-14T15:41:39.652092+09:00 294 [Note] Aborted connection 294 to db: 'test' user: 'root' host: 'localhost' (Got an error reading communication packets)

conn.close() 추가 변경

import pymysql
import sys

def test_sel(col1, col2):
    conn = pymysql.connect(host="localhost", port=3306, user="root", passwd="Rootroot!23", db="rom_test")
    try:
        cur = conn.cursor()
        sql=('select "{0}", "{1}"').format(col1, col2)
        print("excute sql :", sql)
        cur.execute(sql)
        result=cur.fetchall()
    except Exception as e:
        print(title,":",job, " : Exception occured:{}".format(e))
    finally:
        conn.close()
        return result


>>> test_sel('a','b')
('excute sql :', 'select "a", "b"')
(('a', 'b'),)
>>>


-- 에러가 발생하지 않는다.

위와 같은 경우로 고정적인 시작에 발생하는 에러일 경우 반드시 배치작업 소스를 확인해볼 필요가 있다.

 

그외 네트워크 문제로 접속이 끊어지는 경우도 발생할 수 있으으며 아래 자료를 참고하자.

 

dev.mysql.com/doc/refman/8.0/en/communication-errors.html

 

MySQL :: MySQL 8.0 Reference Manual :: B.3.2.9 Communication Errors and Aborted Connections

B.3.2.9 Communication Errors and Aborted Connections If connection problems occur such as communication errors or aborted connections, use these sources of information to diagnose problems: If the log_error_verbosity system variable is set to 3, you might

dev.mysql.com

 

반응형

'Database > Mysql' 카테고리의 다른 글

Mysql / Mariadb에서 쉘명령어 사용하기  (0) 2020.12.14
MariaDB Password 복잡도 설정  (6) 2020.12.14
mysql / mariadb grant 설정  (0) 2020.12.14
MariaDB Audit 설정하기  (0) 2020.12.14
EC2에서 Mariadb 설치하기  (0) 2020.12.14

댓글