작은숲:위키노트/MySQL root 비밀번호 초기화
보이기
MySQL의 root 비밀번호를 잊어버렸다든지 해서 root 비밀번호를 초기화시켜야 할 때가 있다. 이럴 때는 우선 MySQL 서비스를 중지시킨다. 만약 웹 서비스에서 MySQL을 사용한다면 잠시 웹 서버를 내려두는 것이 좋다. MySQL을 사용하는 웹 서비스의 웹 서버를 그대로 두면 아래 작업을 하는 도중 중간중간 MySQL에 접근할 수 없다는 에러 메시지를 출력하게 된다.
# /etc/init.d/mysql stop
Stopping MySQL database server: mysqld.그런 후, /usr/bin/safe_mysqld을 --skip-grant 옵션을 줘서 실행시키면 권한 테이블을 읽지 않게 된다. 따라서 이제 MySQL에 비밀번호 없이 접근이 가능하다. 하지만, 이것은 대단히 위험한 일이므로 빨리 root 비밀번호를 변경한 다음에는 다시 MySQL을 기동시켜야 한다. /usr/bin/safe_mysqld을 실행시킬 때는 백그라운드로 실행시킨다.
# /usr/bin/safe_mysqld --skip-grant &
[1] 28818
Starting mysqld daemon with databases from /var/lib/mysql이제 MySQL에 들어가서 root 비밀번호를 변경한다.
# mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 12 to server version: 3.23.49-log
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> UPDATE user SET Password = PASSWORD('passwd') WHERE user = 'root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye이제 원하는대로 root 비밀번호를 다시 설정했으니 다시 MySQL 데몬을 기동시킨다. 이 상태로 그대로 나둔다면 아무나 MySQL에 접근할 수 있으므로 대단히 위험하다.
# /etc/init.d/mysql restart
Stopping MySQL database server: mysqld
020811 18:28:41 mysqld ended
.Starting MySQL database server: mysqld.
[1]+ Done /usr/bin/safe_mysqld --skip-grant만약 웹 서버를 중지시켜놨다니 이제 다시 가동시키도록 하자.
| 설정과 문제 해결 | |
|---|---|
| 활용 | |