Python2.7 连接Mysql数据库

Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> conn = MySQLdb.connect(host='172.16.67.22',
...                     user='root',
...                     passwd='***********'

...                     db='test')
>>> cursor = conn.cursor()
>>> cursor.execute("SELECT VERSION()")
1L
>>> row = cursor.fetchone()
>>> print "server version:",row[0]
server version: 5.1.66
>>> cursor.close()
>>> conn.close()

你可能感兴趣的:(python数据库)