zoukankan      html  css  js  c++  java
  • 数据库【mysql】之pymysql

    安装模块

    pip install pymysql

    导入模块

    import pymysql

    创建链接

    conn = pymysql.connect(host='192.168.226.150', port=3306, database='python04', user='root', password='123456')

    创建索引

    cursor = conn.cursor()

    查找

    sql = "select * from userinfo"
    cursor.execute(sql)
    r = cursor.fetchone()
    # 获取所有
    # r = cursor.fetchall()
    print(r)

    增加

    sql = "insert into userinfo(username,password) values(%s,%s)"
    # 返回受影响的行数
    r = cursor.execute(sql,['root','123456'])
    print(r)
    conn.commit()
    cursor.close()
    conn.close()

    批量增加  executemany

    sql = "insert into userinfo(username,password) values(%s,%s)"
    # laoer  laoer_pass
    # laosan laosan_pass
    r = cursor.executemany(sql,[('laoer','laosan'),('laoer_pass','laosan_pass')])
    print(r)
    conn.commit()
    cursor.close()
    conn.close()

    修改

    sql = "update userinfo set password=%s where username ='tang'"
    r = cursor.executemany(sql,('456789',))
    conn.commit()
    cursor.close()
    conn.close()

    删除

    sql = "delete from userinfo WHERE username=%s"
    r = cursor.executemany(sql,('root',))
    conn.commit()
    cursor.close()
    conn.close()
  • 相关阅读:
    Unity NGUI实现技能CD效果
    Unity NGUI中Anchor的用法
    Unity 技能按钮触发特效
    Unity NGUI 图集Atlas制作
    Unity NGUI 创建简单的按钮
    Unity 地形
    Unity GUI编程
    Unity 随机数的使用
    linux命令之pssh命令
    MySQL中SQL语句2
  • 原文地址:https://www.cnblogs.com/tangkaishou/p/10223198.html
Copyright © 2011-2022 走看看