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

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
Jina AI
Jina AI
宝玉的分享
宝玉的分享
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
J
Java Code Geeks
博客园 - 【当耐特】
小众软件
小众软件
博客园 - Franky
S
SegmentFault 最新的问题
WordPress大学
WordPress大学
雷峰网
雷峰网
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
Last Week in AI
Last Week in AI
博客园_首页
月光博客
月光博客
IT之家
IT之家
阮一峰的网络日志
阮一峰的网络日志
Webroot Blog
Webroot Blog
Stack Overflow Blog
Stack Overflow Blog
腾讯CDC
云风的 BLOG
云风的 BLOG
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
Recent Commits to openclaw:main
Recent Commits to openclaw:main
D
Docker
The Last Watchdog
The Last Watchdog
有赞技术团队
有赞技术团队
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
DataBreaches.Net
S
Security @ Cisco Blogs
Blog — PlanetScale
Blog — PlanetScale
GbyAI
GbyAI
TaoSecurity Blog
TaoSecurity Blog
S
Security Affairs
Y
Y Combinator Blog
O
OpenAI News
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Forbes - Security
Forbes - Security
P
Palo Alto Networks Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
K
Kaspersky official blog
Cloudbric
Cloudbric

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

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