使用的工具包:pymysql

安装:

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

  pip3 install PyMySQL

github 地址:https://github.com/PyMySQL/PyMySQL

Requirements

  • Python -- one of the following:
  • MySQL Server -- one of the following:

基础使用方法:

 1 # 与数据库建立连接
 2 db = pymysql.connect("localhost", "root", "edward1314", "wordcut")
 3 
 4 #建立执行游标,理解成console那个 '>'
 5 cursor = db.cursor()
 6 
 7 #利用cursor执行sql语句
 8 sql = """insert into word_cut(word,clean_word,cut_list) 
 9             VALUES (%s,%s,%s) 
10             ON DUPLICATE KEY UPDATE
11              cut_list = cut_list"""
12 value = ['a','b','c']
13 cursor.execute(sql, value)

待所有的操作执行完之后,记得要

#关闭链接
db.close

 

简单介绍到这。

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄