Centos Mysql 비밀번호 오류, 분실 시 초기화

2020. 4. 16. 16:43보안 꿀팁

mysql_secure_installation; mysql -u root -p;

비밀번호 미 입력시 오류 : Error: Access denied for user 'root'@'localhost' (using password: NO) 

비밀번호 입력 시 오류 : error: access denied for user 'root'@'localhost' (using password: yes)

- 비밀번호를 잊었을 때에는 안전모드로 들어가 패스워드를 변경해 접속해야 한다.

- 또한 패스워드 변경 후 최조 접속시 한번 더 비밀번호를 변경해야 한다.

1. 비밀번호 변경 및 접속

1) MySQL 중지

systemctl stop mysqld

2) MySQL 환경 옵션 (안전모드 로그인)

systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

3) 시작

systemctl start mysqld

4) 루트 로그인

mysql -u root

50 비밀번호 변경

mysql> UPDATE mysql.user SET authentication_string = PASSWORD('새로운 비밀번호')

-> WHERE User='root' AND Host='localhost';

mysql> FLUSH PRIVILEGES;

mysql> quit

6) 중지

systemctl stop mysqld

7) 환경설정 했던 부분 해제

systemctl unset-environment MYSQLD_OPTS

8) 다시 서비스 시작

systemctl start mysqld

9) 변경한 비밀번호를 입력하면 된다.

mysql -u root -p

2. 최초 접속 시 비밀번호 변경 방법

mysql> alter user 'root'@'localhost' identified by '변경할 비밀번호';