1. MySQL 데몬을 중지 시킨다.
[root@localhost mysql]# killall mysqld (또는 pkill -9 mysqld)
2. --skip-grant 옵션을 주어서 mysql 데몬은 다시 실행시킨다.
[root@localhost mysql]# /usr/local/mysql/bin/safe_mysqld --skip-grant &
Starting mysqld daemon with databases from /usr/local/mysql/var
3. 패스워드 없이 root 계정으로 mysql에 접속한다.
[root@localhost 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. mysql> 프롬프트에서 update 쿼리문으로 패스워드를 재설정 한다.
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)
6. mysql> 프롬프트에서 빠져 나온다.
mysql> quit
Bye
7. mysql 데몬을 재시작 한다.
[root@localhost mysql]# killall mysqld (또는 pkill -9 mysqld)
[root@localhost mysql]# /usr/local/mysql/bin/safe_mysqld &
[1] 10008
[root@localhost mysql]# Starting mysqld daemon with databases from /usr/local/mysql/data
8. 업데이트한 패스워드로 mysql에 접속한다.
[root@localhost mysql]# /usr/local/mysql/bin/mysql -u root -p
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>