Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

1049, "Unknown database 'database' " django mysql can't connect

Exception Type: OperationalError at /
Exception Value: (1049, "Unknown database 'database'")

At the moment i tried this:

DATABASES = {
   'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'database',                      # Or path to database file if using sqlite3.
        'USER': 'root',                      # Not used with sqlite3.
        'PASSWORD': '****',                  # Not used with sqlite3.
        'HOST': '/var/lib/mysql/database/',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '80',                      # Set to empty string for default. Not used with sqlite3.
    }
}

If i don't specify a host i get this error:

OperationalError at /

(2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/database' (13)")

Can it be something with permissions?

thanks in advance :)

like image 937
Tony Avatar asked Dec 12 '22 01:12

Tony


1 Answers

First, create the database on mysql. Second, edit your default conection like this.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'MY_DATABASE_NAME',
        'USER': 'root',
        'PASSWORD': 'MY_PASSWORD',
    }
}

finally run your syncdb.

./manage.py syncdb

like image 92
napstercake Avatar answered Dec 28 '22 22:12

napstercake