Jamgreen
Jamgreen

Reputation: 11039

Django, MySQL, and Cloud9

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.

Upvotes: 1

Views: 1641

Answers (3)

Ibrahim Salah
Ibrahim Salah

Reputation: 1

i'm already have this problem and >> solved you should add your Host name e.g

'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',    } }

Upvotes: 0

Sanzhar Bishmanov
Sanzhar Bishmanov

Reputation: 11

Try this 'HOST':'127.0.0.1'

   'default': {
        'ENGINE': 'django.db.backends.mysql',
        'HOST': '127.0.0.1',
        'USER': 'user_naeme',
        'NAME':'c9',
    }

Upvotes: 1

catavaran
catavaran

Reputation: 45575

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',
    },
}

Upvotes: 1

Related Questions