python對(duì) MySQL 數(shù)據(jù)庫(kù)進(jìn)行增刪改查的腳本
# -*- coding: utf-8 -*-import pymysqlimport xlrd# import codecs#連接數(shù)據(jù)庫(kù)conn = pymysql.connect(host=’127.0.0.1’, port=3306, user=’root’, passwd=’’, db=’test_hvr’, charset=’utf8’)cursor = conn.cursor()# 查詢數(shù)據(jù)庫(kù)effect_row = cursor.execute('select * from kkpb_account where user_name=’18800000000’')row_1 = cursor.fetchmany(10)print(row_1)for row in row_1: with open(’ha.xls’,’a’)as f: f.write(str(row[0]))# print(row[0])# 使用預(yù)處理語(yǔ)句創(chuàng)建表# sql = '''CREATE TABLE EMPLOYEE (# FIRST_NAME CHAR(20) NOT NULL,# LAST_NAME CHAR(20),# AGE INT,# SEX CHAR(1),# INCOME FLOAT )'''# cursor.execute(sql)# 數(shù)據(jù)庫(kù)插入數(shù)據(jù)# s_id=’25’# name=’aaa’# price=’154.21’# sql='insert into stu (id) VALUES (’%s’)'%(s_id,)# add_row=cursor.execute(sql)# 刪除數(shù)據(jù)# name=’asds’# sql='delete from user where name = ’%s’' % name# dele_row=cursor.execute(sql)# 更新數(shù)據(jù)# userid=’10’# sql='update user set price=124.21 where userid=’%s’'%userid# upd_row=cursor.execute(sql)conn.commit()cursor.close()conn.close()
以上就是python對(duì) MySQL 數(shù)據(jù)庫(kù)進(jìn)行增刪改查的腳本的詳細(xì)內(nèi)容,更多關(guān)于python 操作MySQL數(shù)據(jù)庫(kù)的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. PHP使用Swagger生成好看的API文檔2. ASP.NET MVC使用jQuery ui的progressbar實(shí)現(xiàn)進(jìn)度條3. ASP基礎(chǔ)知識(shí)VBScript基本元素講解4. Python3 json模塊之編碼解碼方法講解5. Python 利用Entrez庫(kù)篩選下載PubMed文獻(xiàn)摘要的示例6. Python 制作查詢商品歷史價(jià)格的小工具7. 通過實(shí)例解析Python文件操作實(shí)現(xiàn)步驟8. python使用jenkins發(fā)送企業(yè)微信通知的實(shí)現(xiàn)9. Python 如何調(diào)試程序崩潰錯(cuò)誤10. Python 合并拼接字符串的方法

網(wǎng)公網(wǎng)安備