Sunday, August 09, 2009

Reset MySQL root password


Step 1
root@amir:~# /etc/init.d/mysql stop

Step 2
root@amir:~# /usr/bin/mysqld_safe --skip-grant-tables &
[1] 6709
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6763]: started

Step 3
root@amir:~$ mysql --user=root mysql
Enter password:

mysql> update user set Password=PASSWORD('new-password') WHERE User='root';
Query OK, 2 rows affected (0.04 sec)
Rows matched: 2 Changed: 2 Warnings: 0

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

mysql> exit
Bye

Step 4
root@amir:~# /etc/init.d/mysql start
Starting MySQL database server: mysqld.

Step 5
root@amir:~# mysql --user=root --pass=new-password
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 5.0.24a-Debian_4-log

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

mysql> exit
Bye




No comments: