Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Our previous DBA left and didn't note the root password down, and I've been pressganged into doing part of his job until we can hire someone.

So I create a file :

/root/mysql.password

Inside that file, I have:

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

So I do a clean shutdown of the database, and then:

mysqld_safe --init-file=/root/mysql.password

I get 'starting mysqld' ... and then it exits with code 1.

I don't get it. What's wrong with that file?

Using ..

mysqld_safe --skip-grant-tables &

.. isn't an option, unfortunately, as it's a public-facing production box.

Thanks.

share|improve this question
    
Or wait... is it because the init file has to have more than just an UPDATE in it, since I'm in effect telling the database to bypass /etc/my.cnf? –  John T. Feb 12 at 7:25
    
Have you seen this (the Unix paragraphs)? How to Reset the Root Password –  ypercube Feb 12 at 10:10

2 Answers 2

@John T.

The very first thing you should do is take a backup of your database using mysqldump or similar, because if you mangle something, your root password will be useless anyway.
HTH, Paul...

share|improve this answer
    
Yes, it's a VM so I cloned it before touching it. Yes, I've seen the MySQL doc, and was in fact working from that. –  John T. Feb 12 at 18:30

Different methods to reset 'root' password

1)

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

2)

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('cleartext password');

3)

mysqladmin -u root password 'NEWPASSWORD'
share|improve this answer

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.