一,MySQL-Python插件
Python里操作MySQL数据库,需要Python下安装访问MySQL数据库接口API包即插件,从而使得Python2.7能访问操作MySQL数据库。MySQL软件可以去官网下载:http://www.mysql.com/; MySQLdb插件下载:http://sourceforge.net/projects/mysql-python/files/latest/download
二,访问MySQL数据库
1,连接数据库mysql
基本格式:connect ([host=]'ip',[user=]'user',[passwd=]'password',[db=]'dbname')
2,数据库的基本操作
1)create创建表
1 import MySQLdb 2 #connect to a database 'test' 3 conn=MySQLdb.connect(host='localhost',user='root',passwd='zbc123',db='test') 4 cursor=conn.cursor() 5 #create a table 6 cursor.execute('create table \ 7 test(ID int primary key auto_increment,Name char(25))') 8 #Closing database 9 cursor.close() 10 conn.close()