Python3.4连接Mysql
生活随笔
收集整理的這篇文章主要介紹了
Python3.4连接Mysql
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Python3.4連接Mysql
Python版本:3.4.3
安裝Lib庫:pymysql
?
代碼結(jié)構(gòu)樹:
?
主函數(shù)代碼片dbcheck.py
#!/usr/bin/python # -*- coding: utf-8 -*- import configinit import pymysqldef execute_mysql():conn = Nonecur = Nonetry:conn = pymysql.connect(**configinit._mysql_config)cur = conn.cursor()query = "SELECT * FROM publicnetbarpolicy;"cur.execute(query)result = cur.fetchall()for record in result:print(record)cur.close()conn.close()except pymysql.Error as e:print("Mysql Error %d: %s" % (e.args[0], e.args[1]))if __name__ == '__main__':execute_mysql()?
數(shù)據(jù)庫配置文件__init__.py
#!/usr/bin/python # -*- coding: utf-8 -*-_mysql_config = {'user': 'root','password': 'js*%##))!!WX','host': '10.34.53.172','db': 'netbarapppolicys','charset':'utf8',}?
posted on 2015-06-18 14:01 GoldbachRhapsody 閱讀(...) 評論(...) 編輯 收藏轉(zhuǎn)載于:https://www.cnblogs.com/GoldbachRhapsody/p/4585716.html
總結(jié)
以上是生活随笔為你收集整理的Python3.4连接Mysql的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一群猴子排成一圈,按1,2,...,n依
- 下一篇: 找1的个数