2

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.

2
  • 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.
    Commented Feb 12, 2014 at 7:25
  • Have you seen this (the Unix paragraphs)? How to Reset the Root Password Commented Feb 12, 2014 at 10:10

3 Answers 3

1

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'
1

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.

1
  • 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.
    Commented Feb 12, 2014 at 18:30
0

The problem may have been permissions

You had to run

chown mysql:mysql /root/mysql.password

or

chmod 777 /root/mysql.password

before starting mysqld

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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