$cat insert.py
#!/usr/bin/python
# -*- coding: UTF-8 -*- import os
import sys
import datetime
import pymysql def read_insert(filename, slot_type_id):
file = open(filename)
i = 0
j = 0
list = [] db = pymysql.connect(host="test", user="test", passwd="test", port=3306, db="test", charset='utf8')
cursor = db.cursor() sql = "insert into test(slot_type_id, type, value, gmt_modify, gmt_create) values (%s, %s, %s, %s, %s)" for line in file:
data = (slot_type_id, "const", (line.replace("\n","")),
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
list.append(data) if i > 5000:
cursor.executemany(sql, list)
db.commit()
print("插入", j)
i = 0
list = []
i = i + 1
j = j + 1 if i > 0:
cursor.executemany(sql, list)
db.commit()
db.close()
file.close()
print("ok") if __name__ == "__main__":
read_insert(sys.argv[1], sys.argv[2])

Python3之pymysql导入mysql的更多相关文章

  1. python3使用PyMysql连接mysql数据库

    python语言的3 x完全不向前兼容,导致我们在python2 x中可以正常使用的库,到了python3就用不了了 比如说mysqldb目前MySQLdb并不支持python3 python语言的3 ...

  2. Python3 使用pymysql链接MySQL数据库

    1,pymysql安装 pip install pymysql 2,pymysql使用 import pymysql 3,实例查询 import pymysql #获取一个数据库链接 #格式 主机地址 ...

  3. Python3.x使用PyMysql连接MySQL数据库

    Python3.x使用PyMysql连接MySQL数据库 由于Python3.x不向前兼容,导致Python2.x中的很多库在Python3.x中无法使用,例如Mysqldb,我前几天写了一篇博客Py ...

  4. Python3.x:使用PyMysql连接Mysql数据库

    Python3.x:使用PyMysql连接Mysql数据库 Python3.x完全不向前兼容,导致Python2.x中可以正常使用的库,到了Python3就用不了: 比如说mysqldb,目前MySQ ...

  5. Python3中使用PyMySQL连接Mysql

    Python3中使用PyMySQL连接Mysql 在Python2中连接Mysql数据库用的是MySQLdb,在Python3中连接Mysql数据库用的是PyMySQL,因为MySQLdb不支持Pyt ...

  6. python专题-Mysql数据库(python3._+ PyMysql)

    之前写过一篇 Python使用MySQL数据库的博客,主要使用的是Python2和MySQLdb驱动. python使用mysql数据库 Python2 ---> Python3 MySQLdb ...

  7. python3使用pymysql模块,连接mysql数据库,实现新增、查询和更新操作

    1.环境数据准备: python3环境.pymysql模块 mysql数据库:本次代码中用到的数据库为本地的testdb数据库,user表(表字段比较简单,只有主键id,手机号mobile,密码pas ...

  8. python3实现多excel一键导入mysql

    转载:qq_37955852 一.实现场景. import excel files to mysql author:zxb 工作每个work经常会导入一到几十张不等的excel表,表少可以用navic ...

  9. python3.6 使用 pymysql 连接 Mysql 数据库及 简单的增删改查操作

    1.通过 pip 安装 pymysql 进入 cmd  输入  pip install pymysql   回车等待安装完成: 安装完成后出现如图相关信息,表示安装成功. 2.测试连接 import ...

随机推荐

  1. ThinkPHP学习(二)

    书接前文. 我想前台填写内容,然后在后台保存一下,规划了一下前台要录入的内容,主要包括title.content两大内容.然后简单设计了一个前台页面(复杂的我得会啊),就在上篇文章的基础上直接加了: ...

  2. UICollectionView Demo

    1. 利用系统自动布局UICollectionViewFlowLayout进行布局. ViewController1 #import "ViewController1.h" @in ...

  3. Bean的加载过程

    参考地址: http://blog.csdn.net/jy0902/article/details/50519115 http://blog.csdn.net/architect0719/articl ...

  4. Sails入门指南

    1.全局观:sails理念,框架结构 2.试用sails的scaffolding工具,创建model,创建controller, 3.启动server,试用blueprint, 4.进阶: 4.0 数 ...

  5. 让windows能像ubuntu一样方便的神器

    让windows能像ubuntu一样方便的神器: Let's get Chocolatey! Chocolatey NuGet is a Machine Package Manager, somewh ...

  6. 【转】UML类图符号 6种关系说明以及举例

    转自http://www.cnblogs.com/duanxz/archive/2012/06/13/2547801.html UML中描述对象和类之间相互关系的方式包括:依赖(Dependency) ...

  7. php实现ZIP压缩文件解压缩(转)

    测试使用了两个办法都可以实现: 第一个:需要开启配置php_aip.dll <?php //需开启配置 php_zip.dll //phpinfo(); header("Content ...

  8. 分享十:php中并发读写文件冲突的解决方案

    对于日IP不高或者说并发数不是很大的应用,一般不用考虑这些!用一般的文件操作方法完全没有问题.但如果并发高,在我们对文件进行读写操作时,很有可能多个进程对进一文件进行操作,如果这时不对文件的访问进行相 ...

  9. IOS7 新特性

    相关ios7新特性 帖子.挺全的.一定要看看哪 http://www.devdiv.com/iOS_iPhone-ios_ui_uikit_text_kit_-thread-203631-1-1.ht ...

  10. RecyclerView 与 ItemTouchHelper 实现拖拽效果

    截图 需求 App 开发新的需求,要求 RecyclerView 实现的九宫格样式可以拖拽,松手以后变更位置,类似于手机桌面拖动 app 变更位置. 分析 经过搜索,发现 support 中带有一个类 ...