DBMS/MySQL
MySQL 5.7 root 패스워드 분실시 복구방법
대단한넘
2018. 5. 2. 01:30
자꾸 까먹는 비밀번호 때문에 ㅠ.ㅠ;;;
1. 실행중인 mysqld를 정지하고 mysqld_safe를 이용하여 구동합니다.
mysqld_safe 의 위치는 'whereis mysqld_safe' 로 찾습니다.
옵션은 grant를 무시하라는 옵션인데, --skip-grant-tables 입니다.
root@mysql ~]# /usr/bin/mysqld_safe --skip-grant-tables
2. mysql client를 이용하여 패스워드 없이 mysql db에 접속합니다.
root@mysql ~]# mysql -uroot mysql
3. user 테이블을 업데이트 합니다.
mysql>update user set authentication_string=PASSWORD("새로운 비밀번호"),
-> password_expired='N',
-> plugin='mysql_native_password'
-> where User='root';
Query OK, 2 rows affected, 1 warning (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 1
-> password_expired='N',
-> plugin='mysql_native_password'
-> where User='root';
Query OK, 2 rows affected, 1 warning (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 1
4. 테스트 후 이상없다면 mysqld_safe를 중지하고 정상적인 mysqld 를 실행합니다.