반응형


1. 개요


리눅스 시스템을 사용하다보면 제일 중요한 것이 바로 데이터베이스이다. 그래서 오늘은 센트OS 5.3 에서 MYSQL rpm 버전으로 설치 되었을때 루트 패스워드 분실시 복구 방법에 대하여 알아 보겠다.





2. mysql root 패스워드 복구를 차례로 실행


우선 rpm 버전으로  설치된 가운데  mysqld_safe 라는 명령어를 찾아야 한다. 보통 /etc/rc.d/init.d/에 위치 하고 있다.

그런 다음 다음과 같이 명령어를 내린다.


[root@jhjeon init.d]# /usr/bin/mysqld_safe --skip-grant &
[1] 1613
[root@jhjeon init.d]# Starting mysqld daemon with databases from /var/lib/mysql

그러면서 mysql은 안전모드로 들어간다.


그런다음 다시 다음과 같은 명령어로 접속을 한다.

[root@jhjeon init.d]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.


다음은 mysql 디비 사용으로 옮긴다.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

그리고 나서 가장 중요한 mysql root 계정에 대한 패스워드를 업데이트 할수 있는 명령어를 다음과 같이 내린다.

mysql> update user set password=password('새로운패스워드') where user='root'
    -> ;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 3  Changed: 2  Warnings: 0


저장해 둔 다음 빠져 나온다.

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@jhjeon init.d]#
[root@jhjeon init.d]#


mysql 데몬을 다시 재실행 하고 나서 제대로 접속이 되는 지 확인을 해 본다.



[root@jhjeon init.d]# service mysqld restart
STOPPING server from pid file /var/run/mysqld/mysqld.pid
100415 16:39:57  mysqld ended

MySQL ¸¦ Á¤Áö Áß:                                          [  OK  ]
MySQL (À»)¸¦ ½ÃÀÛ Áß:                                      [  OK  ]
[1]+  Done                    /usr/bin/mysqld_safe --skip-grant


이제 방금 전에 새로운 패스워드로 로그인 해 본다. 로그인에 성공한 것이다.


[root@jhjeon init.d]# 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.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
mysql>
mysql>
mysql> quit
Bye
[root@jhjeon init.d]#


마무리

혹자는 루트 권한이 획득이 되었다 하더라도 디비(db) 루트 패스워드를 알지 못하면 안전하다고 생각할수도 있으나 지금 처럼 안전하지 않다는 것을 확인이 되었다. 이는 센트 os 5.3에서 테스트 해 보았으며 아마도 최신 버전인 센트 os 5.4 에도 마찬가지로 적용이 될 것으로 본다.

자, 그만큼 루트권한을 획득 한다는 것은 시스템에 모든 권한을 가진다는 말과 같은 것이다. 가장 중요한 데이터베이스의 루트 권한까지 획득한다면 일반 계정의 패스워드 변경도 할수 있다는 이야기이다. 시스템 관리자는 이러한 내용을 잘 숙지하여 시스템 보안에 만전을 기하자. @엔시스.



,