I installed LAMP on Ubuntu 12.04 LTS (Precise Pangolin) and then set root password on phpMyAdmin. I forgot the password and now I am unable to login. When I try to change password through terminal I get:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
How can I fix this? I am unable to open LAMP, uninstall it or reinstall it.
In my case it worked by doing some R&D:
I am able to connect to MySQL using
But it's not working with
mysql -u root -p
.I did not find any
bind-address
in my.cnf. So I outcommented the parametersocket=/var/lib/mysql/mysqld.sock
inmy.cnf
which was causing me a problem with login.After restarting the service it went fine:
I am seeing all these answers, but none offer the option to reset the password and no accepted answer. The actual question being he forgot his password, so he needs to reset, not see if it's running or not (installed or not) as most of these answers imply.
To reset the password
Follow these steps (can be helpful if you really forget your password and you can try it anytime, even if you're not in the situation at the moment):
Stop
mysql
Or for other distribution versions:
Start MySQL in safe mode
Log into MySQL using root
Select the MySQL database to use
Reset the password
Flush the privileges
Restart the server
Stop and start the server again
Ubuntu and Debian:
On CentOS, Fedora, and RHEL:
Login with a new password
Type the new password and enjoy your server again like nothing happened
This was taken from Reset a MySQL root password.
Update taken from @Daniel's comment below:
In MySQL 5.7, the password field in mysql.user table field was removed, and now the field name is 'authentication_string', so step 5 should be:
I tried the following steps:
super user
or usesudo
/etc/mysql/my.cnf
using geditbind-address
, and change its value to the database server host machine's IP address. For me, it waslocalhost
or127.0.0.1
sudo service mysql start
And it worked for me.
Somehow the MySQL server process did not create the socket, or the client is looking for the socket in the wrong place.
My first suggestion would be to check if the MySQL server is running. Second suggestion might be, is the MySQL server running on another host? If so, add the
-h <hostname>
flag to your MySQL client in the terminal.If MySQL is indeed running, and running locally, check your
my.cnf
file. There should be a line likeSee if that matches the socket location that you mentioned in your post.
From experience, I would say the most likely scenario is your MySQL server either is not running at all or is not running on the same host as where you run your MySQL client from the terminal.
By experience I say that you need to check if the server is running first and then try configuring MySQL. The last solution is to re-install MySQL.
I had the same issue. Sometimes this happens if your MySQL service is turned down.
So you have to start it: