Welcome 微信登录

首页 / 数据库 / MySQL / 新手进阶 Python连接MySQL代码

我们先来看Python连接MySQL代码:
#!/usr/bin/env python
# -*-coding:UTF-8-*-#这一句告诉python用UTF-8编码
#=========================================================================
#
# NAME: Python MySQL test
#
# AUTHOR: benyur
# DATE  : 2004-12-28
#
# COMMENT: 这是一个python连接mysql的例子
#
#=========================================================================
“”"
 ***** This is a MySQL test *****
 
 select:
  conn=Connection()
  conn.select_db(test)
  cur=conn.cursor()
  cur.execute(select * from user)
  cur.scroll(0)
  row1=cur.fetchone()
  row1[0]
  row1[1]
  row1[2]
  
 insert:
  cur.execute(insert into user (name,passwd) values(enyur,12345))
  cur.insert_id()
  
 update:
  cur.execute(update user set passwd=123456 where name=enyur)
  
 delete:
  cur.execute(delete from user where id=2)
 
 **********************************
“”"
from MySQLdb import *def conn():
 conn=Connection()
 conn.select_db(test)
 cur=conn.cursor()
 cur.execute(select * from user)
 cur.scroll(0)
 row1=cur.fetchone()
 row1[0]
 row1[1]
 row1[2]
def usage():
 print __doc__
if __name__==__main__:
 usage()
MySQLdb下载地址:http://sourceforge.net/projects/mysql-python/
下载解压缩后放到%Python_HOME%Libsite-packages目录中,python会自动找到此包。
MySQLdb基本上是MySQL C API的Python版,遵循Python Database API Specification v2.0。怎样在线配置phpMyAdminOracle同义词管理功能给你带来的惊喜与注意问题相关资讯      mysql 
  • 数据库服务器 MySQL  (08/15/2013 06:50:23)
  • MySQL 5.6 GA 及逃亡潮  (02/08/2013 14:36:35)
  • MySQL 5.5.22、5.1.62、5.0.96全线  (03/22/2012 19:03:49)
  • MySQL Administrator连接VMWare下  (05/24/2013 09:20:58)
  • MySQL 5.1.68 发布  (02/05/2013 08:37:47)
  • CentOS 5.2+MySQL+Heartbeat双机互  (01/29/2012 11:16:55)
本文评论 查看全部评论 (0)
表情: 姓名: 字数