ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'

前端 未结 30 1213
南旧
南旧 2020-12-04 05:14

I installed MySQL on Mac OS X Mountain Lion with homebrew install mysql, but when I tried mysql -u root I got the following error:

相关标签:
30条回答
  • 2020-12-04 05:46

    After working on this for several hours what worked for me was go to /etc/mysql/ and edit the my.cnf file. Add the following

    [client]
    port = 3306
    socket = /var/run/mysqld/mysqld.sock
    
    0 讨论(0)
  • 2020-12-04 05:47

    I have tried every possible way to solve this issue, like ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock, uninstall and reinstall mysql, make sure mysql is running on xampp but none of it still worked.

    Finally, I open up my.cnf (config file) and copy the socket path (make sure to copy the full path else it won't work). Then I perform this command in my terminal

    mysql --socket=/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
    

    Lo, and behold, mysql launchs.

    This solution will only work if your MySQL is shown running on Xampp/Ampps, but in terminal it is still not connecting to the right socket when you have already attempted something like:

    ./mysql -u root
    

    or

    brew services start mysql
    

    I hope this helps!

    0 讨论(0)
  • 2020-12-04 05:47

    In my case right after installing the MAMP accessing mysql from the terminal was giving the same socket error. At the end all it wanted was a restart and it's working.

    0 讨论(0)
  • 2020-12-04 05:49

    I found the solution to my problem. It was indeed because my MySQL server was not running.

    It was caused by MySQL not being correctly set up on my machine, thus not being able to run.

    To remedy this, I used a script which installs MySQL on Mac OSX Mountain Lion, which must have installed missing files.

    Here is the link: http://code.macminivault.com/

    Important Note: This script sets the root password as a randomly generated string, which it saves on the Desktop, so take care not to delete this file and to note the password. It also installs MySQL manager in your system preferences. I'm also not sure if removes any existing databases, so be careful about that.

    0 讨论(0)
  • 2020-12-04 05:50

    For me it was simple as running:

    /usr/local/opt/mysql/bin/mysqld_safe

    instead of mysqld

    0 讨论(0)
  • 2020-12-04 05:50

    I would recommend you to run

      mysql.server start
    

    before going to

      mysql -u root -p
    

    so as to make sure that the mysql server is running before trying to login into it

    This happens many times what you start/restart a machine where by no mysql server is running.

    0 讨论(0)
提交回复
热议问题