代码:

  说明:由于我本机没有安装数据库,数据库是在远程访问的,故地址不是localhost

# __author__ = 'STEVEN'
import pymysql

host = '10.1.1.136'
port = 3306
name = 'root'
pwd = 'root'
db = 'PYTHONDB'
#获得连接
con = pymysql.connect(host=host,user=name,passwd=pwd,db=db,port=port,charset='utf8')
print('ok')
# 创建cursor
cursor = con.cursor()
#开始执行sql
sql = 'select * from STU'
grant = "grant all on *.*  to 'gwb'@'%' identified by 'gwb123'"
stu_li = [('谭浩强','600',1),('麻生','400',2)]
#一次执行多条插入
s = 'insert into STU(name,grade,sch_id) values(%s,%s,%s)'
# effect_row = cursor.executemany(s,stu_li)
cursor.execute(sql)
print(cursor.fetchall())

  

相关文章:

  • 2021-08-12
  • 2021-12-20
  • 2021-12-20
  • 2021-09-24
  • 2021-09-24
  • 2021-09-02
  • 2021-06-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2021-11-21
  • 2021-08-20
  • 2021-06-05
相关资源
相似解决方案