Python·环境搭建
-
官网下载python3.7.3:https://www.python.org/downloads/release/python-373/
-
配置系统环境变量目录:
E:\ldtools\python3.7.3\python.exe
E:\ldtools\python3.7.3\Scripts\pip.exe
python.exe 运行环境
pip.exe 包管理器 -
安装mysql环境包
1. 安装python 2.7的pip curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py python get-pip.py pip install pymysql 2. 安装python 3.7.3的pip pip install pymysql==1.0.2
-
安装ide
配置ide中python运行环境window/preferences
-
测试脚本
#! /usr/bin/env python # -*- coding:utf-8 -*- # __author__ = "ldd" import pymysql conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123456', db='yy') #游标设置为字典类型 cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) cursor.execute("SELECT * FROM shop_customer1") # row_1 = cursor.fetchone() # 游标遍历一条一调显示 row_all = cursor.fetchall() # 查询表中所有数据 print(row_all) # 显示结果以json格式显示 conn.commit() # 事务提交保存 cursor.close() # 游标关闭 conn.close() # 连接关闭