ironsand
ironsand

Reputation: 15141

Can't reset mysql root password

I followed these instructions for resetting the mysql password: https://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

But somehow it doesn't work in my environment.

First, I created a sql file that reset root password like this.

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

And sudo service mysqld stop then sudo mysqld_safe --init-file=/etc/mysql_grant.sql &.

Then I tried to connect database by root mysql -u root -pfoobar, which failed with this error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

Next I tried to use mysqld, but there are not, so I use mysqld_safe instead.

sudo mysqld_safe --skip-grant-tables &, then mysql -u root.

I tried also sudo service mysqld start --skip-grant-tables, then mysql -u root.

But everything fails with same error message.

What can I do to reset root password anything else?

I'm using CentOS release 6.5 (Final) and mysql --version outputs:

mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1

Edit

This is my /etc/my.cnf.

[client]
port                           = 3306
socket                         = /var/lib/mysql/mysql.sock

[mysqld_safe]
socket                         = /var/lib/mysql/mysql.sock

[mysqld]
user                           = mysql
pid-file                       = /var/run/mysql/mysql.pid
socket                         = /var/lib/mysql/mysql.sock
port                           = 3306
datadir                        = /var/lib/mysql

[mysql]
!includedir /etc/mysql/conf.d

And I do have /var/lib/mysql/mysql.sock.

Edit 2

sudo mysqld_safe --init-file=/etc/mysql_grant.sql -S /var/lib/mysqld.sock & gave me this message. Somehow it ends just after stating. sudo mysqld_safe --init-file=/etc/mysql_grant.sql -S /var/lib/mysql.sock & gave me same error.

[1] 4700
140411 17:59:52 mysqld_safe Logging to '/var/lib/mysql/[MYSERVERNAME].err'.
140411 17:59:52 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
140411 17:59:52 mysqld_safe mysqld from pid file /var/run/mysql/mysql.pid ended

Upvotes: 2

Views: 1666

Answers (1)

Aman Aggarwal
Aman Aggarwal

Reputation: 18429

Its not the password reset problem..

Its socket file problem. Kindly set the socket file path in your init file or eplicilty mention it while stating the server.

Thanks

Upvotes: 1

Related Questions