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

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
Microsoft Azure Blog
Microsoft Azure Blog
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Hacker News - Newest:
Hacker News - Newest: "LLM"
Cyberwarzone
Cyberwarzone
Recorded Future
Recorded Future
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Threat Research - Cisco Blogs
Know Your Adversary
Know Your Adversary
Recent Announcements
Recent Announcements
L
LINUX DO - 热门话题
D
DataBreaches.Net
K
Kaspersky official blog
T
Threatpost
F
Full Disclosure
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
S
Securelist
I
Intezer
有赞技术团队
有赞技术团队
罗磊的独立博客
爱范儿
爱范儿
S
Schneier on Security
P
Privacy & Cybersecurity Law Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
LangChain Blog
美团技术团队
G
Google Developers Blog
T
Tor Project blog
Project Zero
Project Zero
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Hacker News
The Hacker News
W
WeLiveSecurity
Engineering at Meta
Engineering at Meta
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
MyScale Blog
MyScale Blog
阮一峰的网络日志
阮一峰的网络日志
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
T
Troy Hunt's Blog

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

毕业快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