제 7강 root 암호를 잃어버렸을 땐

  출처 : http://gwangcom.co.kr

 
 제 7강 root 암호를 잃어버렸을 땐

암호를 잃어버렸을 경우 즉 My-SQL에서 사용하는 root암호가 뭔지 모른다면 다음과 같은 방법으로 바꿀 수 있 다.

1.먼저 My-SQL 데몬을 모두 죽인다.
[root@kebidido mysql] #  killall mysqld

2.-- skip-grant 옵션을 이용해서 권한테이블을 사용하지 않는 옵션으로 데몬을 띄운다.
 [root@kebidido mysql] #  ./bin/safe_mysqld --skip-grant &
Starting mysqld daemon with databases from /usr/local/mysql/data

여기서 My-SQL데몬의 프로세 서를 확인해 보면
[root@kebidido mysql] # ps  -aux | grep mysqld
root 4343 0.0  0.3  1330  626 pts/4  S  03:23 0:00 sh ./bin/safe_mysqld
root 4353 0.0  0.2  2330  626 pts/4  SN  03:23 0:00  /usr/local/mysql
root 4355 0.0  0.2  2330  626 pts/4  SN 03:23 0:00  /usr/local/mysql
root 4356 0.0  0.3  2330  626 pts/4  SN  03:23 0:00  /usr/local/mysql 

이 상태에서는 권한테이블 을 사용하지 않으므로 어떤 호스트에서도 아무런 일반 사용자도 모든 DB 에 접속이 가능하다. 빨리 PASSWORD를 재설정하고 DB를 다시 띄워야 한 다.

3.그럼, 이제는 root권한으로 DB mysql을 이용한다.
  [root@kebidido mysql] #  ./bin/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 970 to server version: 3.22.32

 Type 'help' for help.

 mysql>

4.다음처럼 새로운 root의 암호로 바꾼다.
 mysql> UPDATE user SET Password=PASSWORD('newpasswd') WHERE user='root';
 Query OK,  1  row affected (0.01 sec)
 Row matched:2   Changed:  1  Warnungs:  0

5.그러면 이제 권한 테이블을 다시 읽는다.
 mysql> FLUSH PRIVILEGES;
 Query OK, 0 rows affected (0.05 sec)

mysql 을 빠져나간다.

mysql> \q
Bye

[root@kebido /root] #

 6.MySQL 서버 데몬을 죽여본다.
  그런데 좀 전에 FLUSH PRIVILEGES; 옵션으로 권한이 재 설정 된 상태이므로 조금 전 작업에서 바꾼 암호를 입력해 야 한다.
  [root@kebido /root] #  ./bin/mysqladmin -u root -p******  shutdown
  [root@kebido /root] #  mysqld daemon ended

  [1] + Done            &nb sp;         ./bin/safe_m ysqld  --skip-grant

7.이제는 권한 테이블 을 이용한 원래의 스크립트를 이용 데몬을 다시 띄운다.
[root@kebido mysql] # ./bin/safe_mysqld &
[1] 22341
[root@kebido mysql] # Starting mysqld daemon with databases from /usr/local/mysql/data

[root@kebido mysql] #  

8.자 이제는 바꾼 암 호를 이용해서 mysql 를 사용할 수 있다.
아래의 방법을 그대 로 따라해보자.
 첫번째 방법 # ./bin/mysql -u root -p****** mysql 을 사용해도 되고
 두번째 방법 # ./bin/mysql -u root -p msyql를 쓰면 암호를 물어 본 다.

보안상 두번째 방법이 권 장되고 있다.
 [root@kebido mysql]# ./bin/mysql -u root -p mysql
 Enter password:
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 1 to server version: 3.22.32

Type 'help' for help.

mysql> select host,user from user;

+-----------+---------- +
| host            | user         |
+-----------+--- -------+
| localhost    | root           |
| kebido        | root           |
| localhost    |            &nb sp;     |
| kebido        |            &nb sp;     |
| localhost    | kebido       |
| localhost    | superpan |
| localhost    | kingstar     |
| localhost    | angel         |
+-----------+--- -------+
8 rows in set (0.00 sec)

mysql> \q

자 이제 패스워드 재설정하 는 모든 과정이 마무리 되었다.
어떠한 시스템이든 패스워드 관리는 중요 하다.
유닉스,리눅스,NT,Window 서버 등 자신이 서버관리자라면 위와 같이 패스워드를 잃어버 리는 상황이 발생해서는 안된다.
만일 서버관리자가 되기 위해서 공부 중이라면 패스워드 관리하는 자세부터 배워야 할 것이다.