khalid althwab
khalid althwab

Reputation: 11

how to reset my mysql password in mac os 10.13.3

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

Upvotes: 1

Views: 15310

Answers (2)

CVG
CVG

Reputation: 137

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.

Upvotes: 4

mrmegatheman
mrmegatheman

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

Related Questions