简体   繁体   English

(2002,“无法通过socket连接到本地MySQL服务器'/var/lib/mysql/mysql.sock'(2)”)

[英](2002, “Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)”)

I am running a django based web application with apache. 我正在使用apache运行基于django的Web应用程序。 I am able to connecto to mysql from python and linux shell but, when i run the server i am getting the following error. 我能够从python和linux shell连接到mysql但是,当我运行服务器时,我收到以下错误。 Where am i doing wrong? 我在哪里做错了?

OperationalError at /

(2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)")

Request Method:     GET
Request URL:    http://dev.ls.co.uk/
Django Version:     1.3
Exception Type:     OperationalError
Exception Value:    

(2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'   (2)")

Exception Location:     build/bdist.linux-x86_64/egg/MySQLdb/connections.py in __init__, line 187
Python Executable:  /usr/bin/python
Python Version:     2.4.3

According to this thread on mysql.com : 根据mysql.com上的这个帖子:

There are two things that could go wrong here: 这里有两件事可能出错:

  1. You don't have permissions to access the directory /var/lib/mysql/whatever.sock because mysql is the owner of the folder or 您无权访问目录/var/lib/mysql/whatever.sock,因为mysql是文件夹的所有者或
  2. /path/whatever.sock doesn't exist. /path/whatever.sock不存在。

First, you should know what user apache runs as: try top command to find out the user. 首先,您应该知道用户apache的运行方式:try top命令以找出用户。 Then, use id thatusername command to figure what group it is in. 然后,使用id thatusername命令来确定它所在的组。

Then, you can read an article about debugging this kind of problem . 然后,您可以阅读有关调试此类问题文章

The socket file is not exists. 套接字文件不存在。 You need to restart the mysqld.service Try this: 你需要重启mysqld.service试试这个:

su

systemctl restart mysqld.service systemctl重启mysqld.service

Have you started mysql in different mode? 你有不同的模式启动mysql? if so, you need to kill the process of mysql and use above command. 如果是这样,你需要杀死mysql的进程并使用上面的命令。 grep for mysql process in the process list to see the process id and kill the process grep for mysql进程在进程列表中查看进程id并终止进程

kill process_id kill process_id

and issue previous command to restart service 并发出上一个命令以重新启动服务

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 缺少 mysql.sock; 产生操作错误:(2002,“无法通过套接字连接到本地 MySQL 服务器‘/tmp/mysql.sock’(2)”) - Missing mysql.sock; yielding OperationalError: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)") (2002,“无法通过套接字'/tmp/mysql.sock'(2)连接到本地MySQL服务器”) - (2002, “Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)”) FLASK python web:MySQLdb._exceptions.OperationalError: (2002, “Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)”) - FLASK python web:MySQLdb._exceptions.OperationalError: (2002, “Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)”) (2002,“无法通过套接字'/var/run/mysqld/mysqld.sock'连接到本地MySQL服务器(2)”) - (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)") OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)") - OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)") 无法通过 socket '/tmp/mysql.sock 连接到本地 MySQL 服务器 - Can't connect to local MySQL server through socket '/tmp/mysql.sock Dockerize Django + mySql app: (2002, "Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)") 错误 - Dockerize Django + mySql app: (2002, "Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)") error “无法通过套接字'/var/run/mysqld/mysqld.sock'(2)连接到本地MySQL服务器”) - “Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)”) django无法通过套接字'/var/run/mysqld/mysqld.sock连接到本地MySQL服务器 - django Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock 无法通过Google App Engine上的套接字'/var/run/mysqld/mysqld.sock'连接到本地MySQL服务器 - Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' on Google App Engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM