[size=large]环境:
windows 7
Python 2.6.2
MySQL 5.1
MySQL-python-1.2.2.win32-py2.6
安装过程中出现了一些警告,然后按照http://sourceforge.net/forum/message.php?msg_id=5808948方法改正
仅import MySQLdb无错
但是在连接中报错
AttributeError: 'module' object has no attribute 'connect'[/size]
代码:
[code="Python"]
import MySQLdb
#建立和数据库系统的连接
conn = MySQLdb.connect(host='localhost', user='root',passwd='sa')
#获取操作游标
cursor = conn.cursor()
#执行SQL,创建一个数据库.
cursor.execute("""create database python """)
#关闭连接,释放资源
cursor.close();
[/code]