Linux/CentOS
CentOS7 - Mysql5.7 비밀번호 재설정, 비밀번호 변경
galid1
2018. 12. 31. 14:12
728x90
Mysql5.7 Password Error
- 비밀번호를 잊었을 때에는 안전모드로 들어가 패스워드를 변경해 접속해야 한다.
- 또한 패스워드 변경 후 최초 접속시 한번 더 비밀번호를 변경해야한다.
(centOs7 기준입니다)
$: shell 에서 명령어 기입
mysql> : mysql 접속 후 명령어 기입
1. 비밀번호 변경 및 접속
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;
6) mysql service 중지
$ 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 '변경할 비밀번호';