import pymysql
coon = pymysql.connect(
      host = '127.0.0.1',
      user = 'root',
      passwd = '123456',
      port = 3306, #port必须写int类型
      db = 'mydb',
      charset = 'utf8' #charset必须写utf8,不能写utf-8
    )
cur = coon.cursor()  #建立游标
cur.execute('delete from student where id=5')
cur.execute('insert into student (id, name) values (5,\'张三\')')
coon.commit()
cur.execute("select * from student")
res = cur.fetchall()    #获取结果
print(res)
cur.close()     #关闭游标
coon.close()    #关闭连接

注意,请先PIP 下 pymysql

 

Enjoy :)

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2021-11-21
  • 2021-05-12
  • 2021-12-29
猜你喜欢
  • 2021-10-01
  • 2021-06-06
  • 2022-03-04
  • 2021-12-07
  • 2021-12-10
  • 2021-12-10
  • 2021-12-10
相关资源
相似解决方案