当前位置: 代码迷 >> 综合 >> _mysql_exceptions.OperationalError: **(2002, Can't connect to local MySQL server through socket '/v
  详细解决方案

_mysql_exceptions.OperationalError: **(2002, Can't connect to local MySQL server through socket '/v

热度:36   发布时间:2023-12-08 21:41:03.0


在linux下安装django的时候,python manage.py syncdb 报错,

Validating models...Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x110251450>> Traceback (most recent call last):File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_runself.validate(display_num_errors=True)File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 266, in validatenum_errors = get_validation_errors(s, app)File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 103, in get_validation_errorsconnection.validation.validate_field(e, opts, f)File "/Library/Python/2.7/site-packages/django/db/backends/mysql/validation.py", line 14, in validate_fielddb_version = self.connection.get_server_version()File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 411, in get_server_versionself.cursor()File "/Library/Python/2.7/site-packages/django/db/backends/__init__.py", line 306, in cursorcursor = self.make_debug_cursor(self._cursor())File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 387, in _cursorself.connection = Database.connect(**kwargs)File "build/bdist.macosx-10.7-intel/egg/MySQLdb/__init__.py", line 81, in ConnectFile "build/bdist.macosx-10.7-intel/egg/MySQLdb/connections.py", line 187, in __init__ _mysql_exceptions.OperationalError: **(2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)")**

刚开始我还以为是我mysql配置文件搞错了,于是我核查自己的配置文件,


然后又对比一下果然 不一样,MySQLdb这个模块是独立的,有自己独立的socket,解决的方法就是做个软连接

ln -s /var/lib/mysql/mysql5.sock  /var/lib/mysql/mysql.sock 

接下来 ,重新执行


  相关解决方案