mysql을 오랫동안 사용하지 않았을 경우에 간혹 root패스워드가 기억나질않아서 당황할 때가 있습니다.

특히, 여러대의 시스템을 관리할 경우에는 시스템의 root패스워드와 일반계정 및 MySQL의 root계정과 일반계정등 기억해야할 암호가 수십개씩 되는 경우가 흔히 있습니다.

필자의 경우에도 관리하는 서버가 많은 편에 속하기 때문에 패스워드를 전혀 바꾸지 않을 수는 없고 해서 변경한 후에는 메모하여 잘 보지 못하는 곳에 블랙박스로 보관합니다.

시스템의 root암호를 잊어 버린 경우도 있었으며, MySQL의 root사용자의 암호를 잊어 버린 경험도 많이 있었습니다.

경험있는 시스템관리자라면 시스템의 root나 MySQL의 root의 암호를 잊어 버렸을 때를 대비해서 패스워드를 새로 설정하는 방법을 반드시 숙지하고 있어야 할 것입니다.


1. 실행중인 msyql 종료

[root@kebia_1 bin]# ps -ef | grep mysqld
root      9567     1  0 Mar16 ?        00:00:00 sh ./safe_mysqld
root      9576  9567  0 Mar16 ?        00:00:00 /usr/local/mysql/libexec/mysqld
root      9578  9576  0 Mar16 ?        00:00:00 /usr/local/mysql/libexec/mysqld
root      9579  9578  0 Mar16 ?        00:00:00 /usr/local/mysql/libexec/mysqld

[root@kebia_1 bin]#

[root@kebia_1 bin]# killall mysqld

[root@kebia_1 bin]#


2. grant-table 미사용모드로 mysql시작

[root@kebia_1 bin]# ./safe_mysqld --skip-grant-tables&
[1] 12084

[root@kebia_1 bin]# Starting mysqld daemon with databases from /usr/local/mysql/data

[root@kebia_1 bin]#

[root@kebia_1 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 1 to server version: 3.22.24
Type 'help' for help.

mysql>


3. update문으로 root사용자 패스워드 변경

mysql> update user set password=password('12345') where user = 'root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

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

mysql> exit         
Bye


4. 실행중인 mysql 다시 종료

[root@kebia_1 bin]# ps -ef | grep mysqld
root     12084 11558  0 20:10 pts/2    00:00:00 sh ./safe_mysqld --skip-grant-ta
root     12090 12084  0 20:10 pts/2    00:00:00 /usr/local/mysql/libexec/mysqld
root     12092 12090  0 20:10 pts/2    00:00:00 /usr/local/mysql/libexec/mysqld
root     12093 12092  0 20:10 pts/2    00:00:00 /usr/local/mysql/libexec/mysqld

[root@kebia_1 bin]#

[root@kebia_1 bin]# killall mysqld
mysqld daemon ended
[1]+  Done                    ./safe_mysqld --skip-grant-tables

[root@kebia_1 bin]#


5. 일반모드로 Mysql 재시작

[root@kebia_1 bin]# ./safe_mysqld&
[1] 12102
[root@kebia_1 bin]# Starting mysqld daemon with databases from /usr/local/mysql/data
[root@kebia_1 bin]#
[root@kebia_1 bin]# ps -ef | grep mysql
root     12102 11558  0 20:13 pts/2    00:00:00 sh ./safe_mysqld
root     12108 12102  0 20:13 pts/2    00:00:00 /usr/local/mysql/libexec/mysqld
root     12110 12108  0 20:13 pts/2    00:00:00 /usr/local/mysql/libexec/mysqld
root     12111 12110  0 20:13 pts/2    00:00:00 /usr/local/mysql/libexec/mysqld
[root@kebia_1 bin]#



----------------------------------------------------------------------------------


mysql root 패스워드 분실시 방법


(1) ./killall mysqld (데몬을 모조리 죽임)

(2) ./bin/safe_mysqld --skip-grant &

(3) # mysql

(4) mysql> use mysql;

(3) mysql> UPDATE user SET Password=PASSWORD('변경할 비밀번호') WHERE user='root';

(4) mysql> FLUSH PRIVILEGES;



추가..


실행중인 MySQL 데몬을 정지시킨 후 -Sg (Skip GrantTable)옵션을 주고 MySQL을 기동한다.

sueni@bbung ...]# /etc/rc.d/init.d/mysqld stop 또는

sueni@bbung ...]# mysqladmin -uroot -p shutdown

sueni@bbung ...]# safe_mysqld -Sg --language=korean &

sueni@bbung ...]# mysql
 

위와 같이 Sg 옵션을 주면 사용자 권한을 체크하지 않으므로 MySQL에 접속이 가능해진다.

mysql> update user set password=password(root) where user=root;

위와 같이 Root 패스워드를 업데이트한 후 MySQL데몬을 Sg 옵션없이 정상적으로 기동하도록한다.

Posted by 알 수 없는 사용자
,