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

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

    Run: brew info mysql

    And follow the instructions. From the description in the formula:

    Set up databases to run AS YOUR USER ACCOUNT with:
        unset TMPDIR
        mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
    
    To set up base tables in another folder, or use a different user to run
    mysqld, view the help for mysql_install_db:
        mysql_install_db --help
    
    and view the MySQL documentation:
      * http://dev.mysql.com/doc/refman/5.5/en/mysql-install-db.html
      * http://dev.mysql.com/doc/refman/5.5/en/default-privileges.html
    

    Hope this helps.

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

    Try this

    rm -rf /usr/local/var/mysql && brew postinstall mysql@5.7 && brew services restart mysql@5.7
    
    0 讨论(0)
  • 2020-12-04 05:42

    After trying many solutions, seems like the one that finally did the trick was to connect by IP. No longer file sockets getting deleted randomly.

    Just update your MySQL client config (e.g. /usr/local/etc/my.cnf) with:

    [client]
    port = 3306
    host=127.0.0.1
    protocol=tcp
    
    0 讨论(0)
  • 2020-12-04 05:43

    Running sudo chown _mysql /usr/local/var/mysql/* helped me finally after trying multitude of options from all these SO answers. The issue with permissions probably arose from improper shutdown of the machine.

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

    A lot of other helpful responses here, but nothing fixed this for me. Ultimately nothing I found on this site or others would get any version of MySQL from Homebrew working for me.

    It was super painless to just download the DMG from https://dev.mysql.com/downloads/file/?id=479114 (find the appropriate version you need) and let the wizard install it for me. The only other manual step was adding /usr/local/mysql/bin to my PATH.

    I'd recommend this option if brew is giving you trouble.

    Update - if this still doesn't fix it, try completely purging mysql before installing via DMG. Follow these instructions: https://gist.github.com/vitorbritto/0555879fe4414d18569d

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

    Solutions revolve around:

    • changing MySQL's permissions

      sudo chown -R _mysql:mysql /usr/local/var/mysql
      
    • Starting a MySQL process

      sudo mysql.server start
      

    Just to add on a lot of great and useful answers that have been provided here and from many different posts, try specifying the host if the above commands did not resolve this issue for you, i.e

    mysql -u root -p h127.0.0.1
    
    0 讨论(0)
提交回复
热议问题