记录Django 连接Mysql 以及出现问题

来源:互联网 发布:怎么开个淘宝网店手机 编辑:程序博客网 时间:2024/06/05 15:16

具体步骤

  1. 安装Mysql windows推荐安装Xmapp.因为好用!
  2. 安装python 和 Mysql 之间的链接驱动程序。pip install mysqlclient
  3. 修改settings.py的配置,提供Mysql的连接信息。
DATABASES = {    'default': {        'ENGINE': 'django.db.backends.mysql',        'NAME':'blog',        'USER':'root',        'PASSWORD':'123',        'HOST':'localhost',        'PORT':'3306',    }}

错误:

E:\My_Blog-master>pip install mysqlclient 1.3.10Collecting mysqlclient  Downloading mysqlclient-1.3.10-cp35-cp35m-win_amd64.whl (1.4MB)    100% |████████████████████████████████| 1.4MB 343kB/sCollecting 1.3.10  Could not find a version that satisfies the requirement 1.3.10 (from versions: )No matching distribution found for 1.3.10

解决措施:删掉版本号。E:\My_Blog-master>pip install mysqlclient
结果:
python manage.py makemigrations —>记录变化
python manage.py migrate —>把数据库和mikemigrations出来的日志文件及逆行比较。有差异就更新数据库。
更新中
更新完成


这里写图片描述
错误原因:修改了xmapp中mysql的初始密码,仅仅只在网页中更改,并没有在文件中更改。
因为 xampp 中 phpmyadmin 的登陆方式默认是使用在配置文件的帐号密码登陆。你并没有同时修改过配置文件中的密码,导致你的密码与配置文件里的帐号密码不符,因此出错。

修补措施:
1.MySQL 中的“root”用户设置密码(例如:本机MySQL密码为 123456),请在控制台中使用“mysqladmin”命令。例如:

修补措施:
2.找到xampp下phpMyAdmin下的config.inc.php的配置文件信息
cfg[Servers][i][‘user’] = ‘root’;
cfg[Servers][i][‘password’] = ”; //在这改改
重启MySQL服务后新密码生效!

原创粉丝点击