操作MySQL資料庫查詢所有資料

2021-10-08 22:28:38 字數 1227 閱讀 5508

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

# @time : 2020/8/7 22:01

# @author : bingl

# @email : [email protected]

# @file : 操作mysql資料庫查詢所有資料.py

# @software: pycharm

# @desc :靜,是一種修養。

# 匯入pymysql

import pymysql

# 建立連線

con = pymysql.

connect

(host=

'localhost'

,user

='root'

, password=

'bing'

, port=

3306

,database

='python_db'

)# 建立游標

cur = con.

cursor()

# 編寫查詢的sql

# sql = 'select * from t_student'

sql=

'select * from t_student where age = 23'

try:

# 執行sql

cur.

execute

(sql

)# 處理結果集

students = cur.fetchall(

)for student in students:

sno = student[0]

sname = student[1]

age = student[2]

score = student[3]

print

('sno:'

, sno,

'sname:'

, sname,

'age:'

, age,

'score:'

, score)

print

('查詢所有資料成功'

)except exception as e:

print

(e)print

('查詢所有資料失敗'

)finally:

# 關閉連線

con.

close

()

查詢 MySQL 例項上所有資料庫

除錯環境 centos 7.6 安裝版本 mysql community server 5.6.43 除錯人員 成長的小豬 jason song 通過以下方法我們可以查詢到當前例項中所有的資料庫列表 第一種通過 show 命令查詢 方式一 show databases 第二種通過 show 命令查詢...

SQL Server 查詢資料庫中所有資料庫名錶名

1.查詢資料庫中的所有資料庫名 select name from master sysdatabases order by name 2.查詢某個資料庫中所有的表名 select name from sysobjects where xtype u order by name xtype u 表示所...

sql 查詢所有資料庫 表 字段

sql server 用master資料庫查詢所有的資料庫 use master select name from sysdatabases 用其中的乙個資料庫查詢所有表 use student select id name from sysobjects where type u 根據id查詢某個...