[英]django Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock
I have made a virtual environment and installed following: 我已经制作了一个虚拟环境并安装了以下软件:
sudo apt-get install libmysqlclient-dev
sudo pip install MySQL-python
and my setting is : 我的设置是:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB_NAME',
'USER': 'DB_USER',
'PASSWORD': 'DB_PASSWORD',
'HOST': 'localhost',
'PORT': '3306',
}
} }
and when I do manage.py syncdb
it gives the error saying 2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
并且当我执行
manage.py syncdb
它显示错误消息2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
I dont know whats wrong in here... I searched for it... Mostly I found if I use virtualenvironment then the above setting is enough... Whats wrong in here ??? 我不知道这里有什么问题...我在搜索它...大多数情况下,我发现如果我使用virtualenvironment,那么以上设置就足够了...这里有什么问题???
Install mysql server 安装mysql服务器
sudo apt-get install mysql-server
then create a database for your purposes: 然后为您创建一个数据库:
mysql -u root -p --execute "create database DB_NAME; grant all on DB_NAME.* to DB_USER@localhost identified by 'DB_PASSWORD';"
then you should be fine. 那你应该没事的
I should point out that the confusion of mysql searching for a socket, even if specifying a port, is because mysql defaults to a socket when specifying localhost
as an address, if you want to use tcp/ip then you should put an address like 127.0.0.1
there. 我应该指出,即使指定端口,mysql搜索套接字的混乱也是因为将
localhost
指定为地址时,mysql默认为套接字,如果要使用tcp / ip,则应输入127.0.0.1
这样的地址127.0.0.1
那里。
Your HOST should change to '127.0.0.1', you must start service, especially if you are using xamp or lamp. 您的HOST应该更改为“ 127.0.0.1”,必须启动服务,尤其是在使用xamp或lamp时。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB_NAME',
'USER': 'DB_USER',
'PASSWORD': 'DB_PASSWORD',
'HOST': '127.0.0.1',
'PORT': '3306',
} #Your HOST should change to '127.0.0.1', you must start service, especially if you are using xamp or lamp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.