python deal with mysql
来源:互联网 发布:开一家淘宝店 编辑:程序博客网 时间:2024/06/06 15:37
0. install
yum -y install python-devpip install MySQL-python
这个报名容易记错。是MySQL-python,注意大小写。
1.连接数据库
import MySQLdbdb = MySQLdb.connect ("localhost","username","passwd","DBNAME",charset='utf8')
2.执行sql语句
“`
sqs = “select host from processlist”
cursor = db.cursor()
cursor.execute(sql)
results = cursor.fetchall()
for record in results:
col1 = record[0]
col2 = record[1]
3.close
db.close()
4.doc
文档很短。这是他蛋疼的地方,毕竟外部库。
http://mysql-python.sourceforge.net/MySQLdb.html
最后总结一下workflow
- db = MySQLdb.connect()
- cursor = db.cursor()
- sql = “”
- cursor.execute()
- results = cursor.fetchall()
- do with results
- db.close()
0 0
- python deal with mysql
- python 与网站交互(simple,can't deal with javascript)
- How to deal with deep nested Python list
- strcpy deal with overlapping
- android error deal with
- Deal with READIBMW Error #EJRBK066
- something about deal with string
- How to deal with deadlock.
- zoj1623 Deal with C++ Comments
- swtbot deal with native dialog
- The best way to deal with large files in Python style
- python with mysql
- To deal with RealMedia and Others
- How to deal with Gecko problem.
- How to deal with javadoc createProcess issue?
- How to deal with generation gap
- Deal with WinForm Exception for database applications
- How to deal with International trade outsourcing?
- 欢迎使用CSDN-markdown编辑器
- 【Unity】修改MainMaps 下的offset 的值
- TCP协议要点和难点全解
- 从代码分析Android-Universal-Image-Loader的图片加载、显示流程
- hdu 1864-最大报销额-贪心
- python deal with mysql
- asp.net中session的原理及应用
- 自定义的Segment
- Android学习之路(一)——万事开头难
- Linux学习笔记:1.2 权限管理命令chmod
- 【LeetCode】235. Lowest Common Ancestor of a Binary Search Tree
- 有关服务器协议设计的总结
- C#父类强制转换成子类,子类隐式转换成父类
- android小技巧之不缓存的ViewPager