DB_error

유희선·2025년 2월 15일
0

DB

목록 보기
3/3

1️⃣ 현상황

DB status가 failed 됨

[root@localhost ~]# systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code.
See "systemctl status mysqld.service" and "journalctl -xeu mysqld.service" for details.

[root@localhost ~]# systemctl status mysqld
× mysqld.service - MySQL Server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: d>
     Active: failed (Result: exit-code) since Sat 2025-02-15 17:22:08 KST; 13s >
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
    Process: 48446 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, statu>
    Process: 48481 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status>
   Main PID: 48481 (code=exited, status=1/FAILURE)
     Status: "Server shutdown complete (with return value = 1)"
      Error: 13 (Permission denied)
        CPU: 3.410s

Feb 15 17:22:04 localhost.localdomain systemd[1]: Starting MySQL Server...
Feb 15 17:22:08 localhost.localdomain systemd[1]: mysqld.service: Main process >
Feb 15 17:22:08 localhost.localdomain systemd[1]: mysqld.service: Failed with r>
Feb 15 17:22:08 localhost.localdomain systemd[1]: Failed to start MySQL Server.
Feb 15 17:22:08 localhost.localdomain systemd[1]: mysqld.service: Consumed 3.41>

< 에러 코드 >

[root@localhost ~]# journalctl -xeu mysqld.service
░░ Subject: Resources consumed by unit runtime
░░ Defined-By: systemd
░░ Support: https://wiki.rockylinux.org/rocky/support
░░ 
░░ The unit mysqld.service completed and consumed the indicated resources.
Feb 15 17:24:15 localhost.localdomain systemd[1]: Starting MySQL Server...
░░ Subject: A start job for unit mysqld.service has begun execution
░░ Defined-By: systemd
░░ Support: https://wiki.rockylinux.org/rocky/support
░░ 
░░ A start job for unit mysqld.service has begun execution.
░░ 
░░ The job identifier is 5735.
Feb 15 17:24:19 localhost.localdomain systemd[1]: mysqld.service: Main process exited, code=exited, status=1/F>
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://wiki.rockylinux.org/rocky/support
░░ 
░░ An ExecStart= process belonging to unit mysqld.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 1.
Feb 15 17:24:19 localhost.localdomain systemd[1]: mysqld.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://wiki.rockylinux.org/rocky/support
### ░░ 
░░ The unit mysqld.service has entered the 'failed' state with result 'exit-code'.
Feb 15 17:24:19 localhost.localdomain systemd[1]: Failed to start MySQL Server.
░░ Subject: A start job for unit mysqld.service has failed
░░ Defined-By: systemd
░░ Support: https://wiki.rockylinux.org/rocky/support
░░ 
░░ A start job for unit mysqld.service has finished with a failure.
░░ 
░░ The job identifier is 5735 and the job result is failed.
Feb 15 17:24:19 localhost.localdomain systemd[1]: mysqld.service: Consumed 3.299s CPU time.
░░ Subject: Resources consumed by unit runtime
░░ Defined-By: systemd
░░ Support: https://wiki.rockylinux.org/rocky/support
░░ 
░░ The unit mysqld.service completed and consumed the indicated resources.

2️⃣ 문제원인

정확한 원인을 찾기 위해 error_log로 넘어감
Status: "Server shutdown complete (with return value = 1)"
Error: 13 (Permission denied)

/etc/my.cnf 파일에 error_log가 모인 곳 확인 >> /var/log/mysqld.log

[root@localhost ~]# cat /var/log/mysqld.log
2025-02-15T08:21:40.204111Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2025-02-15T08:21:40.208409Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.4.4) initializing of server in progress as process 48407
2025-02-15T08:21:40.224163Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-02-15T08:21:40.874401Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-02-15T08:21:43.908419Z 0 [ERROR] [MY-010147] [Server] Too many arguments (first extra is ':').
2025-02-15T08:21:43.910417Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2025-02-15T08:21:43.910512Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-02-15T08:21:45.097805Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
2025-02-15T08:21:54.928189Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2025-02-15T08:21:54.931586Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.4.4) initializing of server in progress as process 48443
2025-02-15T08:21:54.934213Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2025-02-15T08:21:54.934267Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2025-02-15T08:21:54.934548Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-02-15T08:21:54.935499Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
2025-02-15T08:22:07.995277Z 0 [System] [MY-015015] [Server] MySQL Server - start.
2025-02-15T08:22:08.385468Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.4.4) starting as process 48481
2025-02-15T08:22:08.399392Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f280a0a0-eb75-11ef-95ab-000c29ed87e6.
mysqld: File '/var/lib/mysql/auto.cnf' not found (OS errno 13 - Permission denied)
2025-02-15T08:22:08.399633Z 0 [ERROR] [MY-010183] [Server] Failed to create file(file: '/var/lib/mysql/auto.cnf', errno 13)
2025-02-15T08:22:08.399661Z 0 [ERROR] [MY-010076] [Server] Initialization of the server's UUID failed because it could not be read from the auto.cnf file. If this is a new server, the initialization failed because it was not possible to generate a new UUID.
2025-02-15T08:22:08.400541Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-02-15T08:22:08.403691Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.4.4)  MySQL Community Server - GPL.
2025-02-15T08:22:08.403762Z 0 [System] [MY-015016] [Server] MySQL Server - end.
2025-02-15T08:24:18.886216Z 0 [System] [MY-015015] [Server] MySQL Server - start.
2025-02-15T08:24:19.255944Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.4.4) starting as process 48570
2025-02-15T08:24:19.266525Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 40816089-eb76-11ef-9ab3-000c29ed87e6.
mysqld: File '/var/lib/mysql/auto.cnf' not found (OS errno 13 - Permission denied)
2025-02-15T08:24:19.266667Z 0 [ERROR] [MY-010183] [Server] Failed to create file(file: '/var/lib/mysql/auto.cnf', errno 13)
2025-02-15T08:24:19.266692Z 0 [ERROR] [MY-010076] [Server] Initialization of the server's UUID failed because it could not be read from the auto.cnf file. If this is a new server, the initialization failed because it was not possible to generate a new UUID.
2025-02-15T08:24:19.267401Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-02-15T08:24:19.270246Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.4.4)  MySQL Community Server - GPL.
2025-02-15T08:24:19.270301Z 0 [System] [MY-015016] [Server] MySQL Server - end.

3️⃣ 문제원인 분석

1) Data dir 사용 불가
-데이터 디렉토리에 기존 파일이 존재하여 초기화 불가능

2025-02-15T08:21:54.931586Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.4.4) initializing of server in progress as process 48443
2025-02-15T08:21:54.934213Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.

2) 권한 문제
-auto.cnf 파일 생성 시, 문제 발생

2025-02-15T08:24:19.266525Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 40816089-eb76-11ef-9ab3-000c29ed87e6.
mysqld: File '/var/lib/mysql/auto.cnf' not found (OS errno 13 - Permission denied)

4️⃣ 해결방법

1) 데이터 디렉토리 정리

rm -rf /var/lib/mysql/*

2) Mysql 초기화

mysqld --initialize --user=mysql --datadir=var/lib/mysql

3) Mysql 서비스 시작

systemctl start mysqld

4) 로그 확인 + 상태(active)

cat /var/log/mysqld.log
profile
가즈아😘

0개의 댓글