MySQL 패스워드 초기화
MySQL 관리자 (root) 패스워드를 잃어버리는 경우 당장 서비스에는 문제가 없을지 모르지만 추후 DB 생성과 MySQL 환경 설정, 계정 권한 변경 등의 작업을 진행할 수 없습니다.
MySQL 데몬 구동 권한을 가지고 있다면 비교적 간단하게 MySQL 관리자 패스워드를 초기화 작업이 가능합니다.
MySQL 패스워드 초기화 하기
1. MySQL 서비스 중지 (운영중인 서버라면 서비스가 중단될 수 있으니 유의합니다.)
소스설치인 경우 $ /etc/init.d/mysqld stop
패키지설치인 경우 $ service mysqld stop
실제 MySQL이 종료되었는지 확인해봅니다. $ ps -ef | grep mysqld |
2. mysqld_safe 실행 (MySQL 안전모드 실행)
-> mysqld_safe는 접속정보 없이 로그인을 할 수 있게 실행하는 방법입니다. 또한 &는 백그라운드로 실행한다는 뜻입니다.
소스 설치 $ /usr/local/mysql/bin/mysqld_safe --skip-grant &
패키지 설치 $ mysqld_safe --skip-grant & |
3. MySQL 에 로그인한 이후 다시 패스워드를 변경할 수 있습니다.
$ mysql -u root mysql
|
4. MySQL root 패스워드 변경
(5.7 미만)
mysql> use mysql; Database changed mysql> set password for 'root'@'localhost' = PASSWORD('변경할패스워드'); 또는 mysql> update mysql.user set password=password('변경할패스워드') where user='root' and Host='localhost'; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye |
(5.7 이상)
mysql> use mysql; Database changed mysql> alter user 'root'@'localhost' identified by '변경할 패스워드'; 또는 mysql> update mysql.user set authentication_string=password('변경할패스워드') where user='root' and Host='localhost'; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye |
5. MySQL 재시작
소스 설치
|
6. 변경한 패스워드로 로그인해보면 정상적으로 로그인 되는것을 확인할 수 있습니다.
$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> |
비교적 간단히 mysql 패스워드 초기화 작업을 진행할수 있으며 변경후 웹 서비스나 다른 서비스에 영향을 줄수 있는 작업이므로 변경후 필히 서비스를 확인 해야 합니다.