python支持对mysql的操作

已经安装配置成功python、mysql

之后根据各自电脑配置选择对应系统的MySQL-python

文件是EXE格式、打开下一步即可

下载地址博主分享下:

http://pan.baidu.com/s/1c2uhVwc

安装成功、在IDLE中输入:

import MySQLdb

查看是否安装成功

下面是一些简单的使用代码:

 1 #!/usr/bin/env python
 2 # -*- coding: utf_8 -*-
 3 
 4 import MySQLdb
 5 import sys
 6 
 7 
 8 class DB:
 9     def __init__(self):
10         pass
11 
12     @classmethod
13     def conn(cls):
14         try:
15             db = MySQLdb.connect(host="localhost", user="root", passwd="123456", db="bug")
16         except Exception, e:
17             print e
18             sys.exit()
19         return db
20 
21 if __name__ == '__main__':
22     u = "chenlei"
23     cursor = DB.conn().cursor()
24     print cursor.execute("select user_password from bug_user where user_name = %s", u)
25     # 返回的结果行数
26     print cursor.fetchone()[0]
27     # 返回的一条结果行
28     cursor.close()

对应的数据库信息:

python学习笔记(mysqldb下载安装及简单操作)

这里博主整理的比较简单、主要是为了总结下这块知识

相关文章:

  • 2022-12-23
  • 2021-05-30
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2021-07-27
  • 2021-06-24
  • 2021-06-29
猜你喜欢
  • 2021-10-13
  • 2022-12-23
  • 2021-06-17
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案