I’m using Django Bitnami Stack on Amazon EC2. I’m attempting to sync the database for the initial setup but I am having problems.
When running the following command I receive an error message:
Python manage.py syncdb
"Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")
I understand this as not being able to establish a connection to MySQL server. However when I run this from the command line I can connect:
Mysql –u root –p // "Then entering my password”
Here are the database settings in settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'djangostack',
'HOST': 'localhost',
'PORT': '3306',
'USER': 'root',
'PASSWORD': 'bitnami'
}
}
I've tried to restart MySQL server using sudo service mysqld restart
but I recieve a message stating that mysql is an unrecognized service.
Here is the my.cnf file:
[mysqladmin]
user=root
[mysqld]
basedir=/opt/bitnami/mysql
datadir=/opt/bitnami/mysql/data
port=3306
socket=/opt/bitnami/mysql/tmp/mysql.sock
tmpdir=/opt/bitnami/mysql/tmp
bind-address=127.0.0.1
[mysqld_safe]
mysqld=mysqld.bin
[client]
port=3306
socket=/opt/bitnami/mysql/tmp/mysql.sock
[manager]
port=3306
socket=/opt/bitnami/mysql/tmp/mysql.sock
pid-file=/opt/bitnami/mysql/tmp/manager.pid
default-mysqld-path=/opt/bitnami/mysql/bin/mysqld.bin
!include /opt/bitnami/mysql/bitnami/my.cnf
Best Answer
Connect to the host
127.0.0.1
rather thanlocalhost
.localhost
has special meaning for MySQL on a Unix based OS.