I am trying to connect to my MYSQL database in my Django project on Cloud9 (c9.io).
At first I have started my database by entering mysql-ctl start
in the console which works all fine. If I'm entering it again I get the message MySQL already running
.
In settings.py
I've updated DATABASES
to the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'c9',
'USER': 'my_username',
'PASSWORD': '',
'HOST': '',
'PORT': '',
},
}
but when I'm running python manage.py syncdb
it results in the error django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
.
What am I doing wrong? I've read that HOST and PORT should be left empty in order to obtain the default values.
Acording to the documentation you should connect to the database with following parameters:
Hostname $IP The same local IP as the application you run on Cloud9
Port 3306 The default MySQL port number
User $C9_USER Your Cloud9 user name
So try to add HOST
/ PORT
values to the DATABASES
setting:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'c9',
'USER': 'my_username',
'PASSWORD': '',
'HOST': 'my_ip',
'PORT': '3306',
},
}
Try this 'HOST'
: '127.0.0.1'
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '127.0.0.1',
'USER': 'user_naeme',
'NAME':'c9',
}
i'm already have this problem and >> solved you should add your Host name eg
'HOST': 'your_username.mysql.your_Host_name.com'
example my host is 'pythonanywhere-services.com' finally
DATABASES = { 'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dataBaseName',
'USER': 'urUser',
'PASSWORD': 'urPass',
'HOST': 'urUser.mysql.your_Host_name.com', } }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.