Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resetting MySQL password & missing mysqld.sock file

Tags:

mysql

sockets

I am trying to run a local mysql server, on my own computer. I have lost the password that I initially set up. When I try to connect to mysql, I get the following error:

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

I have therefore tried these steps to reset my MySQL password, but the line

mysql -u root mysql

returns the same error message:

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

When running the command

mysqladmin -u root -p status I get the following message: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'

Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

I have been checking and the file mentioned (/var/run/mysqld/mysqld.sock) doesn't actually exist. I am not sure what is causing this.

I have tried a couple of solutions online including this, this, this and this but none of this solutions worked for me. I would like to add that mysql-server is installed on my machine.

Any help appreciated. Please accept my apologies if there is any confusion to the above statements. I tried to explain what is happening as much as I can, but I am a beginner and I am clueless as to what is happenening there.

like image 944
Pauline Avatar asked Jun 29 '16 09:06

Pauline


2 Answers

1) Stop the mysql demon process using this command :

sudo /etc/init.d/mysql stop

2) Start the mysqld demon process using the --skip-grant-tables option with this command

sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &

Because you are not checking user privs at this point, it's safest to disable networking. In Dapper, /usr/bin/mysqld... did not work. However, mysqld --skip-grant-tables did.

1) start the mysql client process using this command

mysql -u root

2) from the mysql prompt execute this command to be able to change any password

FLUSH PRIVILEGES;

3) Then reset/update your password

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

4) If you have a mysql root account that can connect from everywhere, you should also do:

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

once have received a message indicating a successful query (one or more rows affected), flush privileges:

FLUSH PRIVILEGES;

Then stop the mysqld process and relaunch it with the classical way:

sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

This is borrowed from https://help.ubuntu.com/community/MysqlPasswordReset , you can check also another method to reset mysql password.

like image 81
Haresh Kumar Avatar answered Oct 18 '22 07:10

Haresh Kumar


Looks like your MySQL server is not running at all. Can you check it?

service mysql status

You need to try restart it and make sure that you can stop and start it using

service mysql stop
service mysql start

If you have any errors post them here please.

like image 26
Tim Connor Avatar answered Oct 18 '22 06:10

Tim Connor