window 7 python 3.7 安装pymysql及用法
2019-01-09 18:03
561 查看
版权声明:作者:jiankunking 出处:http://blog.csdn.net/jiankunking 本文版权归作者和CSDN共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。 https://blog.csdn.net/xunzaosiyecao/article/details/86154561
1、下载安装包,进行安装
https://www.python.org/downloads/windows/
2、打开cmd,输入python,查看python查看版本
3、安装PyMySQL
在cmd命令行中输入以下命令,进行安装
pip install PyMySQL
4、示例
#!/usr/bin/env python # -*- coding: utf-8 -*- import pymysql.cursors import uuid import datetime # 连接配置信息 config = { 'host': '127.0.0.1', 'port': 3306, 'user': 'jiankunking', 'password': '12345678', 'db': 'test', 'charset': 'utf8mb4', 'cursorclass': pymysql.cursors.DictCursor, } # 创建连接 connection = pymysql.connect(**config) counter = 1 n = 1000000 # 执行sql语句 try: with connection.cursor() as cursor: while counter <= n: # 执行sql语句,插入记录 now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') sql = 'INSERT INTO project (project_id, project_name, domain_id, update_man,cluster_id,update_time,create_time,description) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)' cursor.execute(sql, (str(uuid.uuid4()), "test", str(uuid.uuid4()), 'jiankunking', 'QD', now, now, '这是一条测试数据')); # 没有设置默认自动提交,需要主动提交,以保存所执行的语句 connection.commit() # print("第 :" + str(counter)) counter += 1 finally: connection.close();
个人微信公众号:
作者:jiankunking 出处:http://blog.csdn.net/jiankunking
相关文章推荐
- Window环境下Python和Django的安装
- Eric5 IDE for Python在window是下安装
- MondoDB介绍 Python与MongoDB用法,安装PyMongo
- window安装python 的pip模块
- Centos 6.* 安装Python3.7
- 用python3.7安装matlab
- window下python无法安装lxml问题解决
- window安装Python环境
- python环境安装(centos与window10上安装)
- python3+pip软件安装-window-linux-mac-多系统安装
- python tornado window 平台安装
- window 安装 python requests库
- window 安装gdal和python
- Window10+Python3.5安装opencv
- MondoDB介绍 Python与MongoDB用法,安装PyMongo
- window环境下python安装numpy、scipy、matplotlib等科学计算包
- window下安装多个python环境
- eclipse安装python插件(window环境)
- python3.7 安装pip3
- Python第三方Window模块文件的几种安装方法