Python访问MySQL数据库

时间:2024-06-14 09:34:38
#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