python sqlalchemy中create_engine语法用法


 示例:注意['mysql+pymysql://root:123456@localhost:3306/python_db']书写格式不要随意加空格在中间

engine = create_engine('mysql+pymysql://root:123456@localhost:3306/python_db')

参数解释:

dialect -- 数据库类型
driver -- 数据库驱动选择
username -- 数据库用户名
password -- 用户密码
host 服务器地址
port 端口
database 数据库
import pandas as pd
from sqlalchemy import create_engine
import pymysql
# 导入必要三模块
# 查询语句,选出customer2018表中的所有数据
sql = 'select * from customer2018;'
df = pd.read_sql_query(sql, engine)
# read_sql_query的两个参数: sql语句, 数据库连接
df = pd.read_sql_query(sql, engine)
# 输出customer2018表的查询结果
print(df)
runfile('D:/pyexcel/temppandas.py', wdir='D:/testl')
   id       creation_time customer  ... quantity amout_of_money remarks
0  15 2021-04-14 17:46:25       aa  ...      NaN            NaN    None
1  16 2021-04-14 18:10:38       版本  ...      7.0            8.0    aaaa
2  17                 NaT     None  ...      NaN            NaN    None
[3 rows x 13 columns]


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM