python连接mysql

####

python连接mysql

 

###

import pymysqldef favorite_colors():
    config = {
        'user': 'root',
        'password': 'root',
        'host': 'db',
        'port': '3306',
        'database': 'knights'
    }
    connection = pymysql.connect(**config)
    cursor = connection.cursor()
    cursor.execute('SELECT * FROM favorite_colors')
    results = [{name: color} for (name, color) in cursor]
    cursor.close()
    connection.close()

    return results

 

上一篇:pymysql工具类


下一篇:GetFriendsLevelInSteam Tool