一,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()
View Code

相关文章:

  • 2021-12-11
  • 2022-01-01
  • 2022-01-15
  • 2021-11-21
  • 2021-09-22
  • 2021-07-24
  • 2021-10-16
  • 2022-12-23
猜你喜欢
  • 2021-11-21
  • 2021-11-21
  • 2022-12-23
  • 2021-06-06
  • 2021-06-13
  • 2022-12-23
  • 2022-01-01
相关资源
相似解决方案