In [2]: conn = pymysql.connect(host="127.0.0.1",user="root",passwd="123456")
In [3]: conn.query("create database pymysql")
Out[3]: 1
In [5]: conn = pymysql.connect(host="127.0.0.1",user="root",passwd="osyunwei",db="pymysql")
In [6]: conn.query("create table mytb(id int primary key auto_increment,title char(20) not null,keywd char(30))")
Out[6]: 0
In [9]: conn.query("insert into mytb(title,keywd) values('first title','first key')")
Out[9]: 1
In [10]: conn.cursor()
Out[10]: <pymysql.cursors.Cursor at 0x7fb686276710>
In [11]: cs = conn.cursor()
In [12]: cs.execute("select * from mytb")
Out[12]: 1
In [13]: for i in cs:
...: print i
...:
(1, 'first title', 'first key')
pymysql 基本操作
最新推荐文章于 2022-08-19 14:38:12 发布