본문 바로가기
DATABASE

Centos mysql 비밀번호 재설정 방법

by YoonJong 2023. 1. 13.
728x90

명령어를 올바르게 작성했는데 접근에러나 다른 에러가 발생하면 맨 앞에 sudo 를 붙이면 진행된다. 

또는 chmod 로 권한부여

 

1) MySQL 중지

systemctl stop mysqld

 

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

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

 

3) 시작

systemctl start mysqld

 

4) 루트 로그인

mysql -u root

 

5) 비밀번호 변경

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

 

 

혹시나 삭제되면 참고 아래 블로그에서 과정을 가져왔다. 

https://seizedj.tistory.com/84

 

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

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) -

seizedj.tistory.com

 

728x90

댓글