首頁  >  文章  >  後端開發  >  python操作mysql

python操作mysql

巴扎黑
巴扎黑原創
2016-12-03 10:00:37833瀏覽

1.python 2.7.2(安裝版本) 
2.MySQL-python-1.2.3.win32-py2.7  (mysqldb模組) 

#連接資料庫程式碼 
#codingdb=utf-8commcom
import time 
host ='127.0.0.1' 
user ='root' 
passwd ='123456' 
port = 3306 
db_list=[] 
port = 3306 
db_list=[] 
port = 3306 
db_list=[] 
, 3306 port=3306) 
cur=dbcon.cursor() 
#列出所有資料庫 
def check_db(): 
    cur.execute('show data  .append(db [0]) 
    return db_list 
#取得目前資料庫中所有的資料表的清單 
db_list = check_db() 
print db_list 
#使用test資料庫,查詢資料庫下面的所有資料表
print db_list 
#使用test資料庫,查詢資料庫下面的所有資料表
print db_list 
#使用test資料庫,testuse資料庫下面的所有資料表

cur.execute("select database()") 
print "目前資料庫:%s" %cur.fetchall()[0] 
all_table = cur.execute("show tables") 
for tb in cur.fetchall( ): 
    tb_list.append(tb[0]) 
print tb_list 
#查詢資料表userinfo 
userList=[] 
cur.execute("use test") info幫助for shuju in cur.fetchall(): 
    userList.append(shuju) 

print userList 🎜
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn