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

文章详细介绍了在Linux环境下使用Django框架时遇到的Python manage.py syncdb 报错问题,主要原因是MySQLdb模块独立于MySQL配置,通过创建软链接解决此问题,并最终成功执行同步数据库操作。
摘要由CSDN通过智能技术生成


在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_run
    self.validate(display_num_errors=True)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 266, in validate
    num_errors = get_validation_errors(s, app)
  File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 103, in get_validation_errors
    connection.validation.validate_field(e, opts, f)
  File "/Library/Python/2.7/site-packages/django/db/backends/mysql/validation.py", line 14, in validate_field
    db_version = self.connection.get_server_version()
  File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 411, in get_server_version
    self.cursor()
  File "/Library/Python/2.7/site-packages/django/db/backends/__init__.py", line 306, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 387, in _cursor
    self.connection = Database.connect(**kwargs)
  File "build/bdist.macosx-10.7-intel/egg/MySQLdb/__init__.py", line 81, in Connect
  File "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 

接下来 ,重新执行


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值