Python访问MySQL数据库

时间:2014-08-12 21:38:54   收藏:0   阅读:188
#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

 

Python访问MySQL数据库,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!