5

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.

Community
  • 1
  • 1
Pauline
  • 1,902
  • 5
  • 17
  • 30
  • Looks like MySQL server is not running. – Fredster Jun 29 '16 at 09:10
  • Try starting it with these commands... https://coolestguidesontheplanet.com/start-stop-mysql-from-the-command-line-terminal-osx-linux/ – Fredster Jun 29 '16 at 09:10
  • you may follow this https://help.ubuntu.com/community/MysqlPasswordReset – Haresh Kumar Jun 29 '16 at 09:11
  • @FredericoFalcao Thanks, however from my understanding, the line "sudo /etc/init.d/mysql stop" would indeed stop the server, which is required to reset the password. Am I mistaken? – Pauline Jun 29 '16 at 09:12
  • @HareshKumar I tried this solution yesterday, it didn't work. The lines 1 to 4 on the first solution presented worked fine (I only had to replace "password" by "authentication_string" as explain [here](https://stackoverflow.com/questions/30692812/mysql-user-db-does-not-have-password-columns-installing-mysql-on-osx) but I still have the problem today. – Pauline Jun 29 '16 at 09:15
  • @HareshKumar I have also tried their "last resort" solution, and the line `mysqladmin -u root password your-new-password` results in `mysqladmin: connect to server at 'localhost' failed` `error: 'Access denied for user 'root'@'localhost' (using password: NO)` – Pauline Jun 29 '16 at 09:19

4 Answers4

3

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.

Haresh Kumar
  • 406
  • 4
  • 14
  • After perform steps 1-4 you need to execute `FLUSH PRIVILEGES;` and restart mysql daemon. – Haresh Kumar Jun 29 '16 at 09:33
  • 2
    Thanks, I have tried this approach, but after `mysql -u root` I get the error `ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)` which I can't resolve. – Pauline Jun 29 '16 at 09:48
  • Try `sudo dpkg-reconfigure mysql-server-N.N` where N.N is mysql-server version – Haresh Kumar Jun 29 '16 at 10:01
  • 1
    I tried the purge solution but the line `mysqladmin -u root password your-new-password` won't run: `mysqladmin: connect to server at 'localhost' failed` `error: 'Access denied for user 'root'@'localhost' (using password: NO)'`. As for `sudo dpkg-reconfigure mysql-server-N.N` (my version is 5.7), it doesn't seem to help. I get `Checking if update is needed.` `This installation of MySQL is already upgraded to 5.7.12, use --force if you still need to run mysql_upgrade` – Pauline Jun 29 '16 at 10:07
  • 1
    try with this link http://askubuntu.com/questions/760724/16-04-upgrade-broke-mysql-server – Haresh Kumar Jun 29 '16 at 10:17
  • 1
    That last link fixed it! It looks like I had my.cnf files all over the place. Doing that step by step fixed it. Thanks a lot :) – Pauline Jun 29 '16 at 10:40
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/115950/discussion-between-pauline-and-haresh-kumar). – Pauline Jun 29 '16 at 10:46
  • I think the OP is following a similar step-by-step, and during `sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &` I get the error about the socket... – Csaba Toth Jul 11 '18 at 16:52
1

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.

Tim Connor
  • 97
  • 2
0

Reinstalling mysql-server worked for me. (I am using mysql 5.7)

sudo wget http://repo.mysql.com/mysql-apt-config_0.8.9-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.9-1_all.deb
sudo apt-get update
sudo apt-get install mysql-server
mysql_secure_installation
Ruchira
  • 492
  • 4
  • 16
0

first kill user

sudo pkill -u <user>

Then install mysql server

sudo apt install mysql-server

Configure it

sudo mysql_secure_installation

Enter into mysql shell

sudo mysql
Ranish
  • 79
  • 9