使用Python将数据加载到Mysql中 [英] Use Python to load data into Mysql

查看:90
本文介绍了使用Python将数据加载到Mysql中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Python中为Mysql设置表?

is it possible to set up tables for Mysql in Python?

这是我的问题,我有一堆.txt文件要加载到Mysql数据库中.除了可以在phpmyadmin中手动创建表之外,是否可以在Python中全部完成以下操作?

Here's my problem, I have bunch of .txt files which I want to load into Mysql database. Instead of creating tables in phpmyadmin manually, is it possible to do the following things all in Python?

  1. 创建表,包括数据类型定义.
  2. 一个接一个地加载许多文件.我只知道此LOAD DATA LOCAL INFILE命令来加载一个文件.
  1. Create table, including data type definition.
  2. Load many files one by one. I only know this LOAD DATA LOCAL INFILE command to load one file.

非常感谢

推荐答案

是.通常,您要使用的是对象关系映射库.

It is. Typically what you want to do is use an Object-Retlational Mapping library.

在python生态系统中使用最广泛的可能是 SQLAlchemy ,但是发生了很多魔术在其中,因此,如果您想对数据库架构进行更严格的控制,或者正在学习关系数据库,并且希望遵循代码的功能,最好使用Canonical的

Probably the most widely used in the python ecosystem is SQLAlchemy, but there is a lot of magic going on in it, so if you want to keep a tighter control on your DB schema, or if you are learning about relational DB's and want to follow along what the code does, you might be better off with something lighter like Canonical's storm.

编辑:刚想添加.使用ORM的原因是,它们提供了一种非常方便的方式来处理与DB的数据/接口.但是,如果您只想做一个脚本将文本数据转换为MySQL表,那么您可能会更轻松地相处.例如,查看从 MySQL官方网站链接的教程.

Just thought to add. The reason to use ORM's is that they provide a very handy way to manipulate data / interface to the DB. But if all you will ever want to do is to do a script to convert textual data to MySQL tables, than you might get along with something even easier. Check the tutorial linked from the official MySQL website, for example.

HTH!

这篇关于使用Python将数据加载到Mysql中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆