zoukankan      html  css  js  c++  java
  • mysql 批量导入脚本

    mysqldump 单表备份,py还原

    调整下允许的包大小

    max_allowed_packet = 10M

    #!/usr/local/bin/python3
    # coding:utf-8
    
    # ====================================================
    # Author: chang - EMail:changbo@hmg100.com
    # Last modified: 2017-4-28
    # Filename: importmysql.py
    # Description: import sql,base os,pymysql
    # blog:http://www.cnblogs.com/changbo
    # ====================================================
    
    import os
    import pymysql
    
    filelist = []
    listfile = os.listdir('/xxxx/xxxx')
    for line in listfile:
        filelist.append(line)
    
    db = pymysql.connect('x.x.x.x', 'xxx', 'xxxxx', 'xxxxx')
    db.set_charset('utf8')
    
    cursor = db.cursor()
    
    
    i = 0
    for i in range(len(filelist)):
        try:
           commond = open('/xxxx/xxxx/%s' % filelist[i]).read()
           cursor.execute(commond)
           db.commit()
           results = cursor.fetchall()
           print(filelist[i])
        except Exception as e:
           print(e)
           pass
    
    db.close()    

    END!

  • 相关阅读:
    2-SIFT简介
    1-SIFT资源整理
    1-vs2015+opencv 3.2.0配置
    5-load-on-startup
    4-监听器
    3-过滤器
    第09组 Alpha冲刺 (1/6)
    第09组(71) 需求分析报告
    第9组(71) 团队展示
    结对编程作业
  • 原文地址:https://www.cnblogs.com/changbo/p/6781354.html
Copyright © 2011-2022 走看看