Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 superuser.com Jan 16 '10 at 19:09

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

3 Answers 3

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
1  
i keep getting error: access denied for 'root'@localhost . how can i fix this please? –  t q Apr 4 '12 at 20:15
  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';

    FLUSH PRIVILEGES;

For reference: the official mysql docs.

share|improve this answer
1  
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

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:

[client]
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

Your Answer

 
discard

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.