1049,"未知数据库'数据库'"django mysql无法连接

Ton*_*dis 4 python mysql django database-connection amazon-ec2

Exception Type: OperationalError at /
Exception Value: (1049, "Unknown database 'database'")
Run Code Online (Sandbox Code Playgroud)

目前我试过这个:

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.
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我没有指定主机,我会收到此错误:

OperationalError at /

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

它可以是具有权限的东西吗?

提前致谢 :)

Ric*_*les 6

首先,在mysql上创建数据库.其次,像这样编辑你的默认连接.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'MY_DATABASE_NAME',
        'USER': 'root',
        'PASSWORD': 'MY_PASSWORD',
    }
}
Run Code Online (Sandbox Code Playgroud)

最后运行你的syncdb.

./manage.py syncdb


Bur*_*lid 5

PORT不是Web服务器端口,而是数据库端口,3306用于MySQL,HOST是数据库服务器的IP或名称.你可能想要127.0.0.1.

您应该事先使用create database mydatabase charset utf8;mysql提示创建数据库.