常用mysql命令
#建表
mysql> CREATE TABLE pages(id bigint(7) not null auto_increment, title VARCHAR(200),content VARCHAR(1000), created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY(id));
新增数据
mysql> insert into pages(title, content) values ('Test pages title','this is some test page content, it can be up to 10000 characters long.')
更新数据
mysql> update pages set title="a new tile",content='Some new content' where id=1;
导入模块
> pip install pymysql
连接对象conn 与光标对象 cur,实现对msyql的连接跟操作
import pymysql
conn = pymysql.connect(host='127.0.0.1',port=3306,user='root',passwd='root',db='mysql')
cur = conn.cursor() #光标对象
cur.execute('USE test') #执行连接数据库
cur.execute("SELECT * FROM pages WHERE id=1") #查询
print(cur.fetchone(