zoukankan      html  css  js  c++  java
  • python 操作mysql

    # 通过 pymysql 连接mysql
    # pip3 install pymysql
    import pymysql
    # 创建连接
    conn = pymysql.connect(host="192.168.4.4",port=3306,user="root",passwd="12345",db="student")

    # 创建游标
    cursor = conn.cursor()

    # 执行sql,并返回受影响行数
    effect_row = cursor.execute("select * from student")

    # 一条一条取
    # print(cursor.fetchone())
    print(cursor.fetchall())

    data = [
    ("N1","2017-10-11","M"),
    ("N2","2017-10-11","F"),
    ("N3","2017-10-11","F")
    ]
    cursor.executemany("insert INTO student (name,register_data,gender) VALUES(%s,%s,%s)",data)
    conn.commit()

    cursor.close()
    conn.close()
  • 相关阅读:
    hdoj 1002 A + B Problem II
    hdoj 1234 开门人和关门人
    hdoj 2203 亲和串
    nyoj 73 比大小
    81B
    信息传递
    bzoj1787
    最少交换次数
    100803C
    火柴排队
  • 原文地址:https://www.cnblogs.com/dennnnnis/p/7649541.html
Copyright © 2011-2022 走看看