服务器在线 - 服务器软件 - 网站地图 服务器在线,专注于服务器技术!

当前位置:主页 > 编程脚本 > Python > 正文

python pymysql使用方法

时间:2022-07-28    来源:未知    投稿:admin    点击:

例:
import pymysql
con = pymysql.connect(
    host = '58.218.204.111',
    port = 3306,
    user = 'fwqzx',
    password = 'fwqzx1237aD6knyYMSfBnXBA',
    db = 'fwqzx',
    charset = 'utf8'
)
cur = con.cursor()
row = cur.execute('show tables')
#print(row)
#all = cur.fetchall()
#print(all)
selct = cur.execute('SELECT * FROM fwqzx')
all = cur.fetchall()
#print(all)
for row in all:
    id = row[0]
    ip = row[1]
    idc = row[2]
    user = row[3]
    status = row[4]
    print(id,ip,idc,user,status)       #打印要查询的数据
#sql = "insert into gefeng_monitor values (null, '%s', '%s','%s', '%s')" % ("58.218.204.111","徐州电信","石家庄","正常")     #增加一条数据。
#sql = "update gefeng_monitor set status='故障' where ip='58.218.204.78'"    #更新一条数据
##sql = "delete from gefeng_monitor where id=2"   #删除一条数据
try:
    cur.execute(sql)
    con.commit()
except:
    con.rollback()

con.close()

如果您的问题仍未解决,还可以加入服务器在线技术交流QQ群:8017413寻求帮助。


相关内容
最新热点内容