1.安装python3.6.5版本
https://www.python.org/downloads/
2.安装环境变量
PYTHON_HOME:D:\soft\Python36
Path增加:;%PYTHON_HOME%;%PYTHON_HOME%\Scripts;
3.使用Pycharm 进行开发
https://www.jetbrains.com/pycharm/download/#section=windows
社区版(Community)即可。
4.用Python写一个mysql 增删查改
#!/usr/bin/env python
# encoding=utf8
import MySQLdb
conn = MySQLdb.connect(host='127.0.0.1', user='root', passwd='123456', port=3306, charset='utf8')
try:
cursor = conn.cursor()
cursor.execute("drop database if exists tmpdb")
cursor.execute("create database tmpdb")
conn.select_db("tmpdb")
cursor.execute("create table tmptab(c1 int, c2 varchar(20), c3 varchar(20)) ENGINE=InnoDB DEFAULT CHARSET=utf8")
cursor.execute(
"insert into tmptab values(101, '姓名1', 'address1'), (102, '姓名2', 'address2'), (103, '姓名3', 'address3'), (104, '姓名4', 'address4')")
conn.commit(); # 执z行commit后数据才能入库并可见
except:
conn.rollback()
cursor.close() # 关闭指针
conn.close() # 关闭连接