Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I'm working locally, I don't really need to enter my password to access my database. I changed my root password when I first installed mysql, but I don't know how to change my password back. What should I do?

share|improve this question

migrated from Jan 16 '10 at 19:09

This question came from our site for computer enthusiasts and power users.

Rather than removing the password (which may have unpleasant consequences in the future if you happen to expose that server to the wilds), put the current password (and your username) into ~/.my.cnf (or presumably some equivalent location in Windows) that looks like this:

user = root
password = s3kr1t

This gives MySQL the awesome ability to autologin using the credentials provided, without leaving you wide open for unpleasantness in the future.

share|improve this answer
+1 Very good idea! – Coops Jan 17 '10 at 14:42

To change the root password to newpassword:

 mysqladmin -u root -p'oldpassword' password 'newpassword'

To change it so root doesn't require a password:

 mysqladmin -u root -p'oldpassword' password ''

Note: I think it matters that there isn't a space between the -p and 'oldpassword' but I may be wrong about that

share|improve this answer
i keep getting error: access denied for 'root'@localhost . how can i fix this please? – t q Apr 4 '12 at 20:15
works for me: mysqladmin -u root -p'oldpassword' password '' @t q: you must type extactly oldpassword – Bảo Nam Jan 7 at 7:02
  1. Stop mysqld and restart it with the --skip-grant-tables option.
  2. Connect to it using just mysql.
  3. Change the root password:

    UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';


For reference: the official mysql docs.

share|improve this answer
This works but is a brute force way of doing it. This is more for when you don't know the password. – David Jan 16 '10 at 21:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.