python下MySQL的使用

mysql连接

    conn_game = MySQLdb.connect(host=app.config["DATABASE_IP"], user=app.config["DATABASE_USER"], 
    passwd=app.config["DATABASE_PWD"], db=app.config["DATABASE_LOGIN_DB"])

全部查询

    cursor = conn_game.cursor()
    cursor.execute('select id, pid, value from `tb` where id=%s', (uid,))
    prop = cursor.fetchall()

单个查询

  cursor = conn_game.cursor()
  cursor.execute('select id, pid, value from `tb` where id=%s', (uid,))
  row = cursor.fetchone()

更新数据

  cursor = conn_login.cursor()
    sql = "update `tb1` set device=CONCAT(device,'DEL') where id  in (select id from `tb2` where uid in (%s));"
    cursor.execute(sql, (uid,))
    conn_login.commit()
    cursor.close()
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容