Cannot start mysqld_safe to reset root password

34,755

Solution 1

mysqld_safe is the command to start the mysql engine. It's not supposed to do or show anything after the line saying that it's started mysql. Once you've run mysqld_safe, the next step is to run mysql. Because you started mysqld with --skip-grant-tables you won't need to specify a username or password.

You can then give the command to reset root's password. For instructions on how to set a password, see http://dev.mysql.com/doc/refman/5.0/en/set-password.html .

Solution 2

have you tried "mysqld --skip-grant-tables" instead of mysqld_safe? make sure to kill any mysqld threads that didn't die before starting mysqld --skip-grant-tables. Do a ps -ef and grep for mysql, kill -9 any mysql process, then start it --skip-grants-tables.

Share:
34,755
John Peden
Author by

John Peden

I'm a contract JavaScript developer based in Manchester in the UK. I've worked for Booking.com, Co-op the UK government and some much smaller, less well-known clients too. I write about my work and life at https://tweakdigital.co.uk and have published a few podcast episodes over there as well.

Updated on July 09, 2022

Comments

  • John Peden
    John Peden almost 2 years

    I installed MySQL and was playing around with the password settings trying to get Wordpress to connect to it. In doing so, I seem to have hashed my root password and now cannot login.

    I'm trying to reset the password by running

    /etc/init.d/mysqld stop
    

    Then

    mysqld_safe --skip-grant-tables
    

    Which outputs

    Starting mysql daemon with databases from /var/lib/mysql
    

    But then does nothing. It neither succeeds nor fails. I've not got any databases setup so I'd be happy to remove and reinstall mysql if necessary but I tried that to no avail. How can I get back in?

  • John Peden
    John Peden about 12 years
    Didn't try starting it out of safe mode and tried to kill any processes but I couldn't find anything to kill, I'm pretty sure the process must have been running already and the system didn't like being told to start it again. Just confusing that there was no error message.
  • John Peden
    John Peden about 12 years
    It wasn't allowing me to input anything else though, the system would just hang.
  • octern
    octern about 12 years
    Is the entire system hanging? Or do you just mean that the terminal you typed mysqld_safe into didn't do anything? That is what's supposed to happen. You need to open a new terminal and then run mysql.
  • MichaelN
    MichaelN about 12 years
    does the mysqld_safe log anything in the error.log or messages? Is there a mysqld process running after you start it in safe mode or with --skip-grant-tables? if you strace the mysqld pid what does the strace show?