0.查看数据库、表、字段
查询sql:
table_name = 'test'
city = '北京'
sql_select = f'select * from {table_name} where city="{city}"'
要查询的数据库 test, 表 cplusplus,字段 city


接下来开始查询!!!
1.定义连接
# -*- conding: UTF-8 -*-
import pymysql
import pandas
conn = pymysql.Connection(
host='localhost',
port=3306,
user='root',
password='123456',
charset='utf8',
db='test',
)
2.使用fetchall获取数据
- execute 返回查询到的数据量
- fetchall 返回execute查询语句的数据,类型是元组,不包括字段行
def get_data(table_name, city):
cursor = conn.cursor()
sql_select = f'select * from {table_name} where city="{city}"'
data_count = cursor.

最低0.47元/天 解锁文章
6万+

被折叠的 条评论
为什么被折叠?



