python 操作mysql

def query():
    conn= MySQLdb.connect(
        host='localhost',
        port = 3306,
        user='root',
        passwd='1234567',
        db ='tlcb',
        )
    cur = conn.cursor()
    a=cur.execute("select title,body, DATE_FORMAT(timestamp,'%Y~%m~%d %k.%i.%s') A from blog_blogpost")
    info = cur.fetchmany(a)
    print info
    print type(info)
    return info
    cur.close()
    conn.close()

原文地址:https://www.cnblogs.com/hzcya1995/p/13349427.html