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

前端 未结 30 1214
南旧
南旧 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条回答
  • You'll need to start MySQL before you can use the mysql command on your terminal. To do this, run brew services start mysql. By default, brew installs the MySQL database without a root password. To secure it run: mysql_secure_installation.

    To connect run: mysql -uroot. root is the username name here.

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

    In my case it was simply a matter of deleting a lock file.

    sudo rm -f /tmp/mysql.sock.lock
    
    0 讨论(0)
  • 2020-12-04 06:02

    I keep coming back to this post, I've encountered this error several times. It might have to do with importing all my databases after doing a fresh install.

    I'm using homebrew. The only thing that used to fix it for me:

    sudo mkdir /var/mysql
    sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
    

    This morning, the issue returned after my machine decided to shut down overnight. The only thing that fixed it now was to upgrade mysql.

    brew upgrade mysql
    
    0 讨论(0)
  • 2020-12-04 06:03

    Ough, that took me a while to figure out. I saw it in a comment. After installing mysql using brew, and starting the service (perhaps using sudo brew services start mysql) then run:

    $ mysqld
    

    And MySQL should be running for your thereafter.

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

    only this has made the trick for me brew services start --all (after trying all answers)

    0 讨论(0)
  • 2020-12-04 06:03
    1. Uninstall MySQL.
    2. Remove /usr/local/var/mysql/.
    3. Install MySQL.
    0 讨论(0)
提交回复
热议问题