首页 > 代码库 > Python访问MySQL数据库

Python访问MySQL数据库

#encoding: utf-8import mysql.connector__author__ = ‘Administrator‘config={‘host‘:‘127.0.0.1‘,#默认127.0.0.1        ‘user‘:‘root‘,       ‘password‘:‘root‘,       ‘port‘:3306 ,#默认即为3306        ‘database‘:‘test‘,       ‘charset‘:‘utf8‘#默认即为utf8       }if __name__=="__main__":    print(config[‘host‘])    cnx =mysql.connector.connect(user=config[‘user‘],password=config[‘password‘],host=config[‘host‘],port=config[‘port‘],database=config[‘database‘])    cursor =cnx.cursor()    cursor.execute("select * from job")    for _row in cursor.fetchall():        print(_row[1])        pass