django连接MySQL报错django.db.utils.OperationalError: (2006, <NULL>)?

最近想学django,于是照着Django官方文档一步步学,没想到刚到连接数据库,就卡了。
在pycharm上通过django连接MySQL报如图所示错误图片说明图片说明图片说明
网上搜索,试了各种方法,包括改hosts文件和HOST改成127.0.0.1,都不成功。把下面这几行代码注释掉,换成原来的sqlite,就可以成功运行,实在不知道什么原因,请各位大佬帮忙看下怎么解决。
环境:Django2.2.1、MySql8.0
下面是我的setting.py文件。一开始pycharm也连不上Mysql,我改了他的时区,Asia/Shanghai,就可以了,但是Django怎么也连不上

"""
Django settings for webProject project.

Generated by 'django-admin startproject' using Django 2.2.1.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'uri0z)r@kn3p)l%6(9if)1$74kv9ag$p@zadp_p$ph_x0(v9h='

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'polls',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'webProject.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')]
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'webProject.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.sqlite3',
#         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
#     }
# }

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'webcrawler',
        'USER': 'root',
        'PASSWORD': '111111',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'

1个回答

卧槽,搞定了,是mysqlclient的包不对,pycharm安装的是1.3.14,我卸载掉,直接pip install 装上了1.4.4,就好了,pycharm居然没装到最新,服了图片说明

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

2
django中创建表python manage.py makemigrations出现以下错误 ,望大神指导
1
django中 django.db.utils.ProgrammingError: (1146, "Table 'xxx' doesn't exist")的问题
2
初学django报错,views.py中一个path有两个函数
1
django创建项目时,urls.py报错:No module named 'index.urls'
2
Django搭建的网站登录Xadmin时报错:TemplateDoesNotExist: xadmin/views/register.html。
1
Django2.0.4连接sqlser2012数据库报错
0
在VS2017里开发Django项目,在views.py里写中文时提示编码错误
1
已配置django-cors-headers,Django跨域访问json还是不成功
4
django刚入门,创建博客的时候出现这个错误,求解决
2
django启动服务时报错 UnicodeDecodeError: 'utf8' codec can't decode byte 0xcb
1
在虚拟机Ubuntu上安装MYSQL,并用DJANGO连接出现的问题 ,需要怎么解决,报错如下
1
将django从1.5.2升级到1.11,项目中的djblets的最新包只能支持到django1.6,怎么办?
2
python3.7,django 2.21,for...in...Python int too large to convert to C long
2
Django连接数据库报错,Connection to db failed
0
django、subprocess多进程 报错django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
2
使用(Django + uwsgi + nginx),项目部署时,提示无法识别自定义过滤器模板标签‘news_filter’?
1
怎样使用Django从Mysql数据库中,下载数据库内的文件?
2
Django报错:django.server:"GET /favicon.ico HTTP/1.1" 500 59,该如何解决?
1
python从入门到实践中,学习笔记项目,用户登录出错:
0
Django下拉列表提交数据验证form.is_valid()为False,请问该如何解决?