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

前端 未结 30 1215
南旧
南旧 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:50

    just hit "brew services start mysql" in terminal

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

    If you are on OSX and have XAMPP,then please follow these steps:

    Thanks to Jackstine's answer, I was able to do the following:

    $ cat ~/.my.cnf

    [mysql]
    
    # CLIENT #
    port                           = 3306
    socket                         = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
    

    I hope this helps me again when I forget, in the future!

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

    Looks like your mysql server is not started. I usually run the stop command and then start it again:

    mysqld stop
    mysql.server start
    

    Same error, and this works for me.

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

    Below I'm including the latest instructions from brew install mysql so newer searches for this issue can benefit:

    $ brew install mysql
    ==> Downloading https://homebrew.bintray.com/bottles/mysql-5.6.26.yosemite.bottle.1.tar.gz
    ######################################################################## 100.0%
    ==> Pouring mysql-5.6.26.yosemite.bottle.1.tar.gz
    
    To connect:
        mysql -uroot
    
    To have launchd start mysql at login:
      ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
    Then to load mysql now:
      launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    Or, if you don't want/need launchctl, you can just run:
      mysql.server start
    

    In my case I loaded mysql now via launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist and was then able to launch $ mysql and be on my way.

    I hope this helps recent troubleshooters!

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

    Encountered a similar problem after upgrading to Catalina OS. After running mysqld command, I found that there was some issue with the logs file. It could be different for others.

    $ mysqld
    

    Issue was

    2019-10-16T04:58:59.174474Z 0 [ERROR] Could not open file '/var/log/mysql/error.log' for error logging: No such file or directory
    2019-10-16T04:58:59.174508Z 0 [ERROR] Aborting
    

    Resolved it by creating it and applying proper permissions.

    sudo mkdir -p /var/log/mysql
    sudo touch /var/log/mysql/error.log
    sudo chown -R _mysql:mysql /var/log/mysql/
    

    Restart MySQL

    brew services restart mysql@5.7
    

    Issue was resolved.

    mysql -uroot -proot
    
    0 讨论(0)
  • 2020-12-04 05:55

    It's probably because MySQL is installed but not yet running.

    To verify that it's running, open up Activity Monitor and under "All Processes", search and verify you see the process "mysqld".

    You can start it by installing "MySQL.prefPane".

    Here is the complete tutorial which helped me: http://obscuredclarity.blogspot.in/2009/08/install-mysql-on-mac-os-x.html

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