Python 3.6.5 + django + pymysql + MySQL + HeidiSQL + Pycharm
1. 安装Python,建议使用最新版本,当前最新的Python 3.6.5
a) 如果PC机上既安装了Python 2.x和3.x建议,将安装的目录添加到环境变量中
b) 建议修改python.exe为python3.exe
c) 查询Python当前版本
C:\>python3 --version
Python 3.6.5
2. 安装django
a) 执行命令来安装django: python3 -m pip install django
b) 查看django的安装版本,当前版本: 2.0.6
C:\>python3
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(2, 0, 6, 'final', 0)
>>> django.get_version()
'2.0.6'
3. 安装pymysql
a) 执行命令安装pymsql第三方库: python3 -m pip install pymysql
b) 查看pymysql安装版本,当前版本: 0.8.1
C:\>python3
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymysql
>>> pymysql.VERSION
(0, 8, 1, None)
4. 安装mysql
a) 直接下载: https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.11-winx64.zip
b) 解压文件到想要的目录: C:\ProgramData\MySQL
c) 初始化数据库: 在MySQL安装目录的bin目录下执行命令: mysqld --initialize --console2018-06-03T11:19:27.774440Z 0 [System] [MY-013169] [Server] C:\ProgramData\MySQL\bin\mysqld.exe (mysqld 8.0.11)
zing of server in progress as process 39796
2018-06-03T11:19:48.535628Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost:oxLI_ggL,58<
2018-06-03T11:20:00.466310Z 0 [System] [MY-013170] [Server] C:\ProgramData\MySQL\bin\mysqld.exe (mysqld 8.0.11)
zing of server has completed
C:\ProgramData\MySQL\bin> 其中root@localhost:后面的“oxLI_ggL,58<”就是初始密码
d) 安装服务: mysqld --install mysql
C:\ProgramData\MySQL\bin>mysqld --install mysql # 安装服务
Service successfully installed.
C:\ProgramData\MySQL\bin>net start mysql # 启动服务
The mysql service is starting...
The mysql service was started successfully.
e) 更改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NEW_PASSWORD';
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NEW_PASSWORD';
Query OK, 0 rows affected (0.14 sec)
mysql> quit;
Bye
f) 登录数据库查询
C:\>mysql -uroot -p
Enter password: **********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 8.0.11 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases; # 查看当前数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydb |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> select user,host,authentication_string from mysql.user; # 查看新用户
+------------------+-----------+-------------------------------------------+
| user | host | authentication_string |
+------------------+-----------+-------------------------------------------+
| NEW_USER | % | *902F20599ED6D43E1CEE2AA263913A10FF670B8F |
| mysql.infoschema | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| root | localhost | *32B87574218DA539413B04F03C9CB4D14158B03F |
+------------------+-----------+-------------------------------------------+
5 rows in set (0.00 sec)
5. 下载Heidisql,客户端工具
a) 直接下载: https://www.heidisql.com/download.php
b) 注意事项: 提示libmysql.dll找不到错误,找该文件放置在Heidisql同目录下即可!
6. 创建第一个项目
a) 假如在D盘创建mysite项目,执行命令:D:\>django-admin.py startproject mysite
b) 执行命令,运行django服务: D:\mysite>python3 manage.py runserver
D:\mysite>python3 manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s
auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
June 09, 2018 - 11:09:46
Django version 2.0.6, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
c) 打开网址: http://127.0.0.1:8000/