Python访问MySQL数据库

#encoding: utf-8
import 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
上一篇:mysql日志详细解析 [转]


下一篇:【python小记】访问mysql数据库