데이터베이스에 접속하려고 하는데, root 패스워드를 잊어버렸을 경우가 있다.

이런 경우 패스워드를 리셋하는 방법이다. (MariaDB 기준)

 

1. MariaDB서비스 중지

sudo systemctl stop mariadb

 

2. MariaDB를 --skip-grant-tables 옵션을 주어 실행함 (MariaDB service unit file을 수정하여 실행)

- 아래 명령을 실행하면, MariaDB service unit file 이 텍스트 에디터로 열림

sudo systemctl edit --full mariadb

- 해당 파일에서 ExecStart 부분을 찾아 아래와 같이 --skip-grant-tables 옵션을 추가함

ExecStart=/usr/sbin/mysqld --skip-grant-tables $MYSQLD_OPTS

- 파일을 저장하고 텍스트 에디터를 종료함

 

3. MariaDB를 수정된 unit file을 이용하여 실행함

sudo systemctl start mariadb

 

4. 이제 권한체크 없이 어드민 태스크를 실행할 수 있게 됨. 아래와 같이 패스워드 없이 DB 접속 가능해짐

mysql -u root

 

5. MariaDB 서버에 접속하면, 'mysql' 데이터베이스로 스위치함

use mysql;

 

6. root 패스워드를 새로운 패스워드로 설정함

update user set authentication_string=password('new_password') where user='root';

 

7. flush privileges를 하여 변경 사항을 반영시킴

flush privileges;

 

8. MariaDB 서버 접속을 종료함

exit;

 

9. MariaDB 서비스를 중지

sudo systemctl stop mariadb

 

10. MariaDB service unit file 에서, --skip-grant-tables 옵션을 삭제함

- 아래 명령을 실행하면, MariaDB service unit file 이 텍스트 에디터로 열림

sudo systemctl edit --full mariadb

- 해당 파일에서 ExecStart 부분을 찾아, 추가했던 --skip-grant-tables 옵션 삭제함

ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS

- 파일을 저장하고 텍스트 에디터를 종료함

 

11. MariaDB를 재실행함

sudo systemctl start mariadb

 

12. 이제 변경된 패스워드로 root 계정 접속이 가능하다.

mysql -u root -p

1. 문제 상황

mysql 이 자꾸 죽는다거나, 시작이 안되는 경우가 있다.

 

2. 원인 파악

로그파일을 분석했을 때, 아래와 같은 메시지가 있다면 메모리가 부족해서 실행을 못하는 것이다.

InnoDB 버퍼 풀 사이즈가 128M (디폴트 값)로 설정되어 있는데, 이를 수용할 만한 메모리가 부족해서 할당 못하고 fail된 것.

(물리적인 메모리 사이즈 자체가 작거나, 다른 프로그램들이 많이 돌아가고 있어 여유 메모리가 부족하거나, 이유는 다양할 수 있다.)

InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137756672 bytes) failed; errno 12
InnoDB: Completed initialization of buffer pool
InnoDB: Fatal error: cannot allocate memory for the buffer pool
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
[Note] Plugin 'FEEDBACK' is disabled.
[ERROR] Unknown/unsupported storage engine: InnoDB
[ERROR] Aborting

3. 해결책

my.cnf 파일에 innodb_buffer_pool_size 를 낮춘 설정을 추가해 주면 된다. (아래 설정 추가)

64M도 메모리 부족으로 실행 안된다면, 32M, 16M.. 사이즈를 더 낮춰서 저장 후 mysql을 실행해보면 된다.

(메모리가 작아지면 DB 성능이 낮아질 우려는 있다.)

innodb_buffer_pool_size=64M

또는, 사용되지 않는 다른 프로그램이나 데몬들을 종료하거나, 물리적 메모리를 추가해주는 등 전체 메모리를 늘려주는 것도 방법이다.

'DB' 카테고리의 다른 글

[DB] MariaDB 보안 설정  (0) 2024.09.27
[MariaDB] root 패스워드 리셋 방법  (0) 2023.07.19
[DB] MariaDB 인코딩  (0) 2023.02.10
[SQLite] SQLite DB 한계  (0) 2022.04.03
데이터베이스(DB) vs. 데이터베이스 관리 시스템(DBMS)  (0) 2021.12.20

+ Recent posts