Tuesday, May 19, 2009

How to reset Password in mysql

Change you own password
login into mysql

at the "mysql>" prompt, type:
set password = password("yournewpassword");

Change other user password
SET PASSWORD FOR 'bob'@'%' = PASSWORD('yournewpassword')

Reference
12.4.1.6. SET PASSWORD Syntax

Addition information
Friend feedback and say he follow the instruction but change password fail! why ??
SET PASSWORD FOR 'user1'@'%localhost' = PASSWORD('yournewpassword')

We can check from here
login into mysql server
mysql> use mysql;
mysql> select user,host from user;

user | host |
+-------------+----------------------+
| root | mysqlserver
| user1 | localhost
| user2 | %

If we login and root and want change password for user1,
we should run this
SET PASSWORD FOR 'user1'@'localhost' = PASSWORD('yournewpassword')

if we want change password for user2,
we should run this
SET PASSWORD FOR 'user2'@'%' = PASSWORD('yournewpassword')