在linux環境下用python2操作mysql

2021-10-03 11:26:43 字數 1055 閱讀 2935

有時候需要在伺服器上通過python指令碼運算元據庫,這時就有乙個問題,linux上預設安裝的python2.7,但是沒有操作mysql指令碼需要的相關模組。

解決:wget

2、安裝pip

3、利用pip安裝運算元據庫的pymysql模組

安裝好了之後,就可以用python指令碼運算元據庫了。附上乙個指令碼

# -*- coding: utf-8 -*-

import pymysql

conn = pymysql.connect(host="ip",port=3307,user="root", passwd="123", db="db")

cursor = conn.cursor()

sql="select id,name_short from project where type in (15,17) "

cursor.execute(sql)

projects = cursor.fetchall()

for project in projects:

#切換到資料庫

sqlcustomer="use ssb_customer_"+str(project[0])

cursor.execute(sqlcustomer)

sqlquerydraft="select count(1) from ssb_r_draft_version"

cursor.execute(sqlquerydraft)

draftcount = cursor.fetchall()

if draftcount[0][0]>0:

print(project[1])

在linux下搭建git環境

1 建立github賬號,2 linux建立ssh金鑰 plain view plain copy ssh keygen 一直預設就可以了 3 將公鑰加入到github賬戶資訊account settings ssh key 4 測試驗證是否成功。plain view plain copy ssh ...

在linux環境下配置SeetaFace環境

參考了以下博文 主要參考這篇文章,非常感謝 1.安裝 公升級cmake 安裝cmake sudo apt get install cmake 公升級cmake sudo apt get upgrade 安裝完後,用命令 cmake version 檢視當前的cmake版本 2.安裝opencv 2 ...

redis在linux環境下配置

wget 3 解壓 tar xzf redis 3.2.9.tar.gz 4 進行編譯 make make install make 編譯 make install 編譯安裝 如果make執行成功就執行make install 編譯完成之後會在 usr local bin目錄下產生以下檔案 5 編輯...