Missing mysql.sock; yielding OperationalError: (2002, “Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)”)

后端 未结 4 656
悲哀的现实
悲哀的现实 2020-12-19 21:38

Firstly, I swear that I have looked at every single question that references this error. Nearly every solution someone offers is different, and no one seems to understand th

相关标签:
4条回答
  • 2020-12-19 22:07

    You have the mysql client installed but not the mysql-server that handles connections for the client. You need to install the mysql server and run it.

    0 讨论(0)
  • 2020-12-19 22:08

    You need to change host to "127.0.0.1" DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'database_name.mwb', # Or path to database file if using sqlite3. 'USER': 'user', # Not used with sqlite3. 'PASSWORD': 'PASS', # Not used with sqlite3. 'HOST': '127.0.0.1', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. }}"

    0 讨论(0)
  • 2020-12-19 22:11

    As far as I can tell, it is either of the two things:

    1. You MySQL Server is not running, or
    2. It is running, but is not configured to use /tmp/mysql.sock as its socket

    As far as 2 is concerned, I believe that is the default setting for a freshly installed MySQL, but it doesn't hurt to check. Try looking at the contents of /etc/my.cnf. Check whether there is a line that looks like this: socket=/path/to/socket - where /path/to/socket is, as it says the file path of the socket. If there is such an entry and the file path is different than /tmp/mysql.sock, you've found your problem. Change either that line, or your Django config so they match.

    Note: In case you don't find /etc/my.cnf you can create it yourself and add the appropriate socket settings (i.e. just add the line socket=/tmp/mysql.sock) just to make sure it's properly configured.

    As far as 1 is concerned, you can follow the instructions available here and make sure your MySql server is running.

    Good luck!

    0 讨论(0)
  • As I answered here:

    with

    mysql_config --socket
    

    I found out where mysql socket is, I apply it:

    'HOST': '/Applications/MAMP/tmp/mysql/mysql.sock',
    
    0 讨论(0)
提交回复
热议问题