when connecting to mysql database in Django ,I get the error.
I'm sure mysql server is running.
/var/run/mysqld/mysqld.sock doesn't exist.
When I run $ find / -name *.sock -type s
, I only get /tmp/mysql.sock and some other irrelevant output.
I added socket = /tmp/mysql.sock
to /etc/my.cnf. And then restared mysql, exited django shell, and connected to mysql database. I still got the same error.
I searched a lot, but I still don't know how to do.
Any help is greate. Thanks in advance.
Well, I just tried some ways. And it works. I did as follows.
socket = /tmp/mysql.sock
.Restart the mysql server.ln -s /tmp/mysql.sock /var/lib/mysqld/mysqld.sock
I met an another problem today. I can't login to mysql. I'm newbie to mysql. So I guess mysql server and client use the same socket to communicate. I add socket = /var/mysqld/mysqld.sock
to [mysqld] [client] block in my.cnf and it wokrs.
It means either the MySQL server is not installed/running, or the file mysql. sock doesn't exist in /var/lib/mysql/ . There are a couple of solutions for this error. Then try to connect again.
normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.
"Try" to run mysql via /etc/init. d/mysql start if it gives you the exact same error from above then you need to copy the mysql. server file from the mysql you downloaded which can be found in the support-files folder inside the mysql folder you downloaded or in the /usr/local/mysql folder and copy it to /etc/init.
Use "127.0.0.1", instead of "localhost"
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'django', 'USER': 'root', 'PASSWORD': '', 'HOST': '127.0.0.1', 'PORT': '3306', } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With