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

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

    This happened after the homebrew install and occurs due to permission issues. The following commands fixed the issue.

    sudo chown -R _mysql:mysql /usr/local/var/mysql
    
    sudo mysql.server start
    
    0 讨论(0)
  • 2020-12-04 05:58

    This fixed my issue when I restarted the mysql service. Just run:

    brew services start mysql
    
    0 讨论(0)
  • 2020-12-04 05:58

    this problem related to /usr/local/var/mysql folder access, I remove this folder and reinstall mysql.

    1. uninstall mysql with brew :

      brew uninstall mysql

    2. sudo rm -r /usr/local/var/mysql

    3. brew install mysql@8.0
    4. mysql -u root

    This solution works fine for me! BUT YOU LOST ALL YOUR DATABASES! WARNING!

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

    Warning - this method will remove all of your databases in the /usr/local/var/mysql folder

    I had MySQL installed with Homebrew, and the only thing that fixed this for me was re-installing MySQL.

    On my company laptop, I didn't have permission to uninstall MySQL from my computer via Homebrew:

    $ brew uninstall mysql --ignore-dependencies
    Uninstalling /usr/local/Cellar/mysql/8.0.12... (255 files, 233.0MB)
    Error: Permission denied @ dir_s_rmdir - /usr/local/Cellar/mysql/8.0.12
    

    So instead, I removed and reinstalled MySQL manually:

    $ sudo rm -rf /usr/local/Cellar/mysql
    $ brew cleanup
    $ sudo rm -rf /usr/local/var/mysql
    $ brew install mysql
    

    And that worked!

    0 讨论(0)
  • 2020-12-04 06:01

    As others have pointed out this is because MySQL is installed but the service isn't running. There are many ways to start the MySQL service and what worked for me is the below.

    To start the service:

    1. Go to "System Preference"
    2. At the bottom pane there should be MySql icon.
    3. Double click that to launch the 'MySQL Server Status' and press the button 'Start MySQL Server'

    My env:

    Mac Yosemite 10.10.3

    Installed Package: /Volumes/mysql-advanced-5.6.24-osx10.8-x86_64

    0 讨论(0)
  • 2020-12-04 06:01

    I went through this issue and I managed to run mysql server using below solution

    Install mysql through .dmg(https://dev.mysql.com/downloads/mysql/5.7.html), you will get mysql service panel in system preferences then start mysql from the panel and try

    mysql -u root -p

    Images attached for reference

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