Reputation: 11
I have a problem with MySQL. I forgot the password I used when I installed it so, I can not access to the server now. I tried deleting the MySQL and install it again but it didn't show the password again. So I tried to do it by the terminal and this is the result ... first i stopped the MySQL server
then i put sudo /usr/local/mysql/bin/mysqld_safe –skip-grant-tables
in the terminal
after that in new terminal window i wrote sudo /usr/local/mysql/bin/mysql -u root
UPDATE mysql.user SET Password=PASSWORD('root') WHERE User='root';
FLUSH PRIVILEGES;
\q
the result was "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)"
these are all the commands
Upvotes: 1
Views: 15310
Reputation: 137
You can try reseting the root password by running MySQL in Safe Mode.
Here are the steps:
Stop MySQL:
sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
sudo mysqld_safe --skip-grant-tables
This will be an ongoing command until the process is finished so open another shell/terminal window, and..
Log in without a password as root:
mysql -u root
Update root (and any other user's) password)
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
\q
Restart MySQL in normal mode
sudo /usr/local/mysql/support-files/mysql.server start
Reference: https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/
Note: this is pretty standard reset procedure, but just documented better in the above guide compared to mysql reference docs.
Upvotes: 4
Reputation: 86
Try this command. I believe you should have mysql running. If that doesn't work try with mysql stopped.
sudo mysql_secure_installation
Hopefully should get you to prompt a password change.
Also, for the socket error, you can try following this link. Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Upvotes: 5