Use python311+pycharm community edition+MySQL80, use django to connect to MySQL
1. Download
1.1. Official website download python
https://www.python.org/downloads/
Such as my python3.11.4, you can enter the following page for hash verification
https://www.python.org/downloads/release/python-3114/
1.2. Download pycharm from the official website
https://www.jetbrains.com.cn/pycharm/download/
1.3. Download MySQL from the official website
https://dev.mysql.com/downloads/windows/installer/8.0.html
2. Install
2.1. Install python
2.1.1. Check add python.exe to path to enter customiz installation
2.1.2. next
2.1.3. Install for all users, then you can simplify the python installation path, install
2.1.4. Cancel the path length limit
2.1.5. Open cmd and enter python to view the version, and exit after reading exit().
2.1.6. Python installation completed
2.2. Install pycharm community edition
2.2.1. next,next
2.2.2. Check all, install
2.2.3. Restart to complete the final installation
2.2.4. Reopen pycharm, user agreement, data sharing
2.2.5. Sinicization. plugins—Chinese language pack—install—Restart IDE
2.2.6. The installation of pycharm community edition is completed
2.3. Install MySQL
2.3.1. I can’t speak well, so I will put a detailed tutorial from Baidu below
https://blog.csdn.net/YX_0719/article/details/130624633
3. Create a django project to connect to MySQL
3.1. Create django using pycharm community edition
3.1.1. New project
3.1.2. By default, virtualenv is used to create a virtual machine environment. The virtual environment is in the newly created folder, which can be modified by yourself, and click Create
3.1.3. Use pip list to view installed components
3.1.4. Here, first configure an Ali source for pip, otherwise the pip download will be very slow, connect as follows
https://blog.csdn.net/m0_37787392/article/details/124067316
3.1.5. Use the pip install django command to download django, and use pip list to view the installed
3.1.6. Use the django-admin startproject xxx command to create a django project file
3.1.7. Use cd xxx to enter the django project directory, and then use python manage.py startapp xxx to create an app application
3.1.8. Use the python manage.py runserver localhost:8080 command to run the service, and you can open the link with a browser, as shown in the figure.
3.1.9. Use the button of pycharm to quickly run the service. After setting, click the green triangle button to quickly switch the service
3.2. Create a django project to connect to MySQL
3.2.1. Find setting.py and configure the new app in INSTALLED_APPS
3.2.2. Configure MySQL connection parameters in DATABASES
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'xxx',
'USER':'root',
'PASSWORD':'123',
'PORT':3306,
'HOST':'127.0.0.1',
'CHARSET':'utf8'
}}
3.2.3. Use pip install pymysql to install the module in the terminal
3.2.4. Add the following code in the __init__.py file of the django project
import pymysql
pymysql.version_info=(1,4,3,"final",0) # 指定了pymysql的版本:1.4.3,按照你版本修改
pymysql.install_as_MySQLdb()
3.2.5. Then use MySQL 8.0 Command Line Client - Unicode to create a new database, which can be found in the win key
Enter password: ***********
!!!输入账号密码
!!!创建数据库
mysql> create database blog0611;
Query OK, 1 row affected (0.00 sec)
!!!查看数据库,已有新建
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| blog0611 |
| information_schema |
| mysql |
| performance_schema |
| sakila |
| sys |
| world |
+--------------------+
7 rows in set (0.00 sec)
!!!使用数据库
mysql> use blog0611;
Database changed
!!!查看表,现在django数据未迁移,为空
mysql> show tables;
Empty set (0.00 sec)
3.2.6. Use cd in the terminal of pycharm to enter the django project folder, and enter python manage.py migrate to perform data migration
3.2.7. Then you can see the new django-related data table items in the database at mysql
mysql> show tables;
+----------------------------+
| Tables_in_blog0611 |
+----------------------------+
| auth_group |
| auth_group_permissions |
| auth_permission |
| auth_user |
| auth_user_groups |
| auth_user_user_permissions |
| django_admin_log |
| django_content_type |
| django_migrations |
| django_session |
+----------------------------+
10 rows in set (0.00 sec)
3.2.8. At this point, you're done, use the quit; command to exit the database, and you can close the project in the file in the upper left corner of pycharm.
You can also use a higher version of navicat to connect to mysql80 for management. I won't show it here, because it needs scientific means to use it for free, and I don't need it for the time being.