python连接mysql

发布时间:2019-06-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了python连接mysql脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

example

#coding=UTF-8

import Sys
import MySQLdb
import time

reload(sys)
sys.setdefaultencoding('utf-8')

def connectDemo():
    return MySQLdb.Connection("127.0.0.1","root","root","demo",3306,charset="utf8")


if __name__ == '__main__':
    begin=time.time()

    conn=connectDemo()
    cursor = conn.cursor()
    sql="""
        show tables
        """
    count = cursor.execute(sql)
    rows = cursor.fetchall()
    cursor.close()
    conn.close()
    PRint "========demo库共:%s 张表============" % (count)

    print '耗时:%s 秒' % (time.time()-begin)

脚本宝典总结

以上是脚本宝典为你收集整理的python连接mysql全部内容,希望文章能够帮你解决python连接mysql所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。