Skip to content

Instantly share code, notes, and snippets.

@kanikash4
Created June 7, 2018 17:31
Show Gist options
  • Save kanikash4/efc7ff99aca4b8a41f8626ac771d5d8a to your computer and use it in GitHub Desktop.
Save kanikash4/efc7ff99aca4b8a41f8626ac771d5d8a to your computer and use it in GitHub Desktop.
Mysql Error: ERROR 2002 (HY000)
Mysql installed but throwing error while using command `mysql -u root -p`
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
But while checking in `/tmp/mysql.sock` there is no mysql in tmp
Perform the following steps:
1. sudo chown -R _mysql:mysql /usr/local/var/mysql
It will prompt for system password, enter the password.
2. sudo mysql.server start
Starting MySQL
.Logging to '/usr/local/var/mysql/kanikasharma-MacBook-Pro-2.local.err'.
. SUCCESS!
Now access with `mysql -u root -p`
If forgotten the password, go through the below mentioned steps:
1. mysql -u root
2. mysql> USE mysql
3. mysql> UPDATE mysql.user SET authentication_string=PASSWORD("<new-password>") WHERE User='root';
4. mysql> FLUSH PRIVILEGES;
5. Exit it and re open in other tab.
It works !
@kanikash4
Copy link
Author

One more way found:

  1. brew services start MySQL
    It will successfully start MySQL service. Now you can connect to the server.

2.mysql -uroot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment