Aug 11, 2011

Reset mysql password

Reset mysql password

[vuhung@ ~]$ sudo /etc/init.d/mysqld stop
Shutting down MySQL. SUCCESS!

[vuhung@ ~]$ sudo /usr/local/mysql/bin/mysqld_safe
--datadir=/usr/local/mysql/data
--pid-file=/usr/local/mysql/data/server.pid --skip-grant-tables &
[1] 18802
[vuhung@ ~]$ 110811 03:04:32 mysqld_safe Logging to
'/usr/local/mysql/data/server.err'.
110811 03:04:32 mysqld_safe Starting mysqld daemon with databases from
/usr/local/mysql/data


[root@dragon525 ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.14-log Source distribution

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

mysql> use mysql;
Database changed
mysql> update user set password=PASSWORD("*****") where User='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0

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

mysql> quit
Bye

[vuhung@ ~]$ ps -ef | grep mysql
root 18802 18387 0 03:04 pts/0 00:00:00 /bin/sh
/usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data
--pid-file=/usr/local/mysql/data/server.pid --skip-grant-tables
mysql 19090 18802 0 03:04 pts/0 00:00:00
/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql
--datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin
--user=mysql --skip-grant-tables
--log-error=/usr/local/mysql/data/server.err
--pid-file=/usr/local/mysql/data/server.pid --socket=/var/tmp/mysql.sock
--port=3306
vuhung 19111 18387 0 03:09 pts/0 00:00:00 grep mysql

[vuhung@ ~]$ sudo kill -9 18802 19090
[1]+ 強制終了 sudo /usr/local/mysql/bin/mysqld_safe
--datadir=/usr/local/mysql/data
--pid-file=/usr/local/mysql/data/server.pid --skip-grant-tables
[vuhung@ ~]$ sudo /etc/init.d/mysqld start
Starting MySQL SUCCESS!

[vuhung@ ~]$ sudo su -
[root@525 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.14-log Source distribution

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

mysql>


cf. http://www.cyberciti.biz/tips/recover-mysql-root-password.html

No comments: