1.PHP网页
2.MySQL的使用方法
命令行:
直接在终端或cmd中敲命令
Web工具:
phpmyadmin:简单、轻量、好用
新建数据库
新建数据表、定义字段(Int、Float、Varchar、Text)
本地软件:
Navicat:功能更强大
数据的导入、导出
使用代码:
mysql-python:读写更新数据
我的习惯:
使用phpmyadmin新建数据库和数据表(本地)
使用python插入、读取、更新数据(数据操作)
使用Navicat导出数据库(mysql文件)
使用phpmyadmin导入数据库(mysql文件导入阿里云服务器)
3.使用Python操作MySQL
MySQLdb:
安装:pip install mysql-python
加载包 :
import MySQLdb
import MySQLdb.cursors
建立连接:
db = MySQLdb.connect(host='127.0.0.1', user='root', passwd='root', db='douban', port=8889, charset='utf8', cursorclass = MySQLdb.cursors.DictCursor)
db.autocommit(True)
cursor = db.cursor()
执行操作:
CURD
cursor.execute(sql)
关闭连接:
cursor.close()
db.close()
cursor.execute("insert into movie(title,url,rate,length,description) values(%s,%s,%s,%s,%s)", [line[0],line[1],line[2],line[3],line[-3]])
cursor.execute("update movies set title=%s,length=%s where id=1" , ['hehaunlin', 999])
cursor.execute("select * from movies")
movies=cursor.fetchall()
print movies
print movies[0]
cursor.execute("delete from movies where id=%s",[1])