1

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 first

then i put sudo /usr/local/mysql/bin/mysqld_safe –skip-grant-tables in the terminal

second

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)"

third

these are all the commands

fourth

1
  • You should include the errors or result of your command as text, not give an external link. Commented Feb 7, 2018 at 23:31

2 Answers 2

5

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)

Sign up to request clarification or add additional context in comments.

Comments

4

You can try reseting the root password by running MySQL in Safe Mode.

Here are the steps:

  1. Stop MySQL:

    sudo /usr/local/mysql/support-files/mysql.server stop

  2. 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..

  1. Log in without a password as root:

    mysql -u root

  2. Update root (and any other user's) password)

    FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass'; \q

  3. 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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.