zoukankan      html  css  js  c++  java
  • python连接mysql数据库

    # -*- coding:utf-8 -*-
    '''
    pymysql操作mysql实践,参考 http://www.cnblogs.com/wupeiqi/articles/5713330.html
    '''

    import pymysql
    import random

    # 创建连接
    conn = pymysql.connect(host='172.16.64.3', port=3306, user='jt_test', passwd='cBTFW@4a2Lpn', db='jt_user_center', charset='utf8')

    # 创建游标
    cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # 使用字典类型获取游标数据

    # 执行SQL,并返回受影响行数

    count=0
    for i in range(1, 100000000):
    user_id = 600000000000000000 + i
    company_id = random.randint(400000000000000001,400000000001000001) # 隶属100w个公司
    tel = 15000000000+random.randint(10000000,50000000)
    openid = 500000000000000000+i # 性别

    cursor.execute('''
    insert into user_info(`user_id`,`company_id`,`nick_name`,`head_img_url`,`tel`,`sex`,`wx_id`,`openid`,`country`,`province`,`city`)
    values(%s, %s, 'tommy','https://img.huxiucdn.com/article/1234.jpg', %s,'0','test155', %s,'中国','广东','深圳');
    ''', (user_id, company_id, tel, openid))
    count += 1
    if (count == 10000):
    print("已写入%s数据..." % i)
    conn.commit()

    count += 1
    if(count==10000):
    print("已写入%s数据..."% i)
    conn.commit()
    count=0


    # 提交,不然无法保存新建或者修改的数据s
    conn.commit()

    # 关闭游标
    cursor.close()
    # 关闭连接
    conn.close()

  • 相关阅读:
    分布式和集群
    c++ >>
    c++ ip地址相关
    c++ ip地址的操作 c版
    c++ 缺少动态库
    c++ dirname() basename()
    shell ulimit -n
    shell 进程查询相关的命令
    shell grep 高亮
    c++ swap 函数
  • 原文地址:https://www.cnblogs.com/perTest/p/9607092.html
Copyright © 2011-2022 走看看