惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
小众软件
小众软件
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
L
LangChain Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
Docker
Cyberwarzone
Cyberwarzone
腾讯CDC
V
Vulnerabilities – Threatpost
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
AWS News Blog
AWS News Blog
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
MyScale Blog
MyScale Blog
C
CERT Recently Published Vulnerability Notes
T
Threat Research - Cisco Blogs
S
Securelist
C
Cybersecurity and Infrastructure Security Agency CISA
Security Archives - TechRepublic
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
Security Latest
Security Latest
N
News and Events Feed by Topic
Attack and Defense Labs
Attack and Defense Labs
V
Visual Studio Blog
博客园 - 司徒正美
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
I
Intezer
P
Privacy International News Feed
爱范儿
爱范儿
T
The Exploit Database - CXSecurity.com
O
OpenAI News
云风的 BLOG
云风的 BLOG
博客园_首页
雷峰网
雷峰网
M
MIT News - Artificial intelligence
Project Zero
Project Zero
I
InfoQ
Hacker News: Ask HN
Hacker News: Ask HN
C
Cyber Attacks, Cyber Crime and Cyber Security
N
News and Events Feed by Topic
S
Security Affairs
S
Secure Thoughts
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
美团技术团队
The GitHub Blog
The GitHub Blog
B
Blog
H
Hacker News: Front Page

博客园 - 朕也就是个普通人

毕业快11年了,我仍是程序猿 平凡的生活~ 反思亲子相处~ cxf RESTful service client cucumber 加油 重新学习python爬虫 python 网址 《高兴》 贾平凹 摘抄 funny python ML 算法 tensorflow 机器学习(Machine Learning) Eureka 注册中心 和 Config中心 配置 最近的日子-2019/8/12 工作上的态度 保持运动 对心情很重要 读《Linux命令行与shell脚本编程大全.第3版》 我的老妈挺可爱 看看书
Python + sqlalchemy + Pandas + Mysql 实现自动创建表,插入数据
朕也就是个普通人 · 2020-08-19 · via 博客园 - 朕也就是个普通人

python 脚本示例:

import pandas as pd
import mysql.connector
from sqlalchemy import create_engine

data = pd.DataFrame({'name': ['User 周', 'User 李', 'User 王']})
engine = create_engine("mysql+mysqlconnector://root:123456@localhost:3306/testdb?charset=utf8")
data.to_sql("test_table", engine, index=False)

运行上段代码,在数据库中会新增test_table表,但是因为插入中文,会遇到编码的exception。

so 需要把mysql数据库编码修改为 utf8bm4: 可参照此链接

https://blog.csdn.net/qq_35028064/article/details/83657264

请注意,配置修改后,需重启数据库服务才生效,重启数据库服务命令:

net stop mysql

net start mysql

不同数据库使用sqlalchemy, 参考:

https://docs.sqlalchemy.org/en/13/core/engines.html