Having trouble resetting mysql root password

I am trying to reset my mysql root password using the following approach:

/etc/init.d/mysql stop
mysqld_safe --skip-grant-tables &
mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("newrootpassword") where User='root';
mysql> flush privileges;
mysql> quit
/etc/init.d/mysql stop
/etc/init.d/mysql start

However, when I execute

/etc/init.d/mysql stop

I get ..

Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql stop

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the stop(8) utility, e.g. stop mysql

So then I try..

sudo service mysql stop

And then when I try to restart mysqld with

mysqld_safe --skip-grant-tables &

I get..

121111 07:32:29 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
121111 07:32:29 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

[1]  + 24469 done       mysqld_safe --skip-grant-tables

Then when I try to connect as root, I get..

 ~  mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I'm not really sure where to go from here. I'd appreciate any help.

Thanks!

1 Reply

Hmm, it looks like either the mysqld process you're starting with mysqld_safe is exiting, or it's not listening on the expected socket.

You can check if the process is still running with ps awwwx | grep [m]y. If it is, try connecting to it over a network port instead: mysql -u root –protocol=TCP -P 3306. If it isn't, look at the log files for an idea as to why it's exiting.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct