我有一个django项目连接到一个mysql数据库,如下所示:
设置.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'my_db',
        'USER': 'username',
        'PASSWORD': 'mypassword',
        'HOST': '',
        'PORT': '',
    }
}

在运行python manage.py syncdb时,它创建数据库,在runserver时,应用程序运行良好,我能够使用管理面板正确地向模型输入数据。
但是,在尝试使用mysql工作台连接到数据库时,它给了我
Can't connect to MySQL server on '127.0.0.1' (111)错误。
我创建的数据库如下:
Grant all on my_db.* to 'username'@'localhost' identified by 'mypassword';
flush privileges;

为什么Workbench会在服务器正常运行的情况下显示该错误?提前谢谢!
编辑:用了pythong这个词。

最佳答案

我也遇到过类似的问题,但通过将端口和主机更新到配置文件中解决了这个问题。

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'vres',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'root',
        'PASSWORD': 'root',
        'HOST': '127.0.0.1',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '3306',                      # Set to empty string for default.
    }
}

关于python - 使用工作台连接到Django中的MySQL数据库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23482185/

10-09 00:51
查看更多