将 CSV 文件转换为 Mysql (.sql) 数据库文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14951400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:37:31  来源:igfitidea点击:

Convert CSV file To Mysql (.sql) database file?

mysqlsqlphpmyadmin

提问by Nimesh Vagadiya

I am using : WampServer 2.2, Apache Version :2.2.21, PHP Version : 5.3.8, MySQL Version :5.5.16, PhpMyadmin Version: 3.4.5...

我正在使用:WampServer 2.2,Apache 版本:2.2.21,PHP 版本:5.3.8,MySQL 版本:5.5.16,PhpMyadmin 版本:3.4.5...

I have face Problem Of Importing CSV file-(size 13MB*), Error File is Too large... phpMyadmin allow only 2MB file size ...

我遇到了导入 CSV 文件的问题 -(大小 13MB*),错误文件太大... phpMyadmin 只允许 2MB 文件大小...

So Separate files with 1.83MB file size...then also it does not work ???

所以用 1.83MB 文件大小的单独文件......然后它也不起作用???

And also tell me , How to automatic create table through CSV file ...?

还告诉我,如何通过 CSV 文件自动创建表...?

回答by Bhavik Shah

Why dont you try to import file using MySQL Console?
I think, you will not face any problem this way. You will not need to split the file into chunks. Just take care of syntax.

为什么不尝试使用 MySQL 控制台导入文件?
我想,这样你不会遇到任何问题。您不需要将文件拆分成块。只需注意语法。

load data infile 'c:/filename.csv' into table tablename fields terminated by ',';

For details about syntax, refer Load Data Infileon official documentation.
For example, refer thisand this.

有关语法的详细信息,请参阅官方文档中的Load Data Infile
例如,参考thisthis

Hope it helps!!!

希望能帮助到你!!!

回答by Dheeraj Avvari

LOAD DATA INFILE 'your.csv' INTO TABLE android_dev FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 ROWS;

LOAD DATA INFILE 'your.csv' INTO TABLE android_dev FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 ROWS;

include the csv file in your database folder,i.e., <root>\mysql\data\DATABASE_NAME

将 csv 文件包含在您的数据库文件夹中,即, <root>\mysql\data\DATABASE_NAME

回答by Geo Systems

I'd suggest you look at Data Transformer(disclaimer - I'm its developer). It can convert CSV/JSON/XML to SQL. The generated SQL contains "insert" statements for each line and a "create table" statement.

我建议您查看Data Transformer(免责声明 - 我是它的开发人员)。它可以将 CSV/JSON/XML 转换为 SQL。生成的 SQL 包含每行的“插入”语句和“创建表”语句。

The app works offline and your data never leaves your computer.

该应用程序可离线运行,您的数据永远不会离开您的计算机。

You can get it from the Mac App Storeor the Microsoft Store.

您可以从Mac App StoreMicrosoft Store获取它。

回答by Abhimanyu

One of the best option which i frequently use is rebasedata, they allow around 200 MB (CSV to MySQL, which I tested) in their free plan.

我经常使用的最佳选择之一是 rebasedata,他们的免费计划允许大约 200 MB(CSV 到 MySQL,我测试过)。

Checkout yourself here https://www.rebasedata.com/convert-csv-to-mysql-online

在这里检查自己https://www.rebasedata.com/convert-csv-to-mysql-online

回答by Sham

Go to ..\xampp\php\php.ini

转到 ..\xampp\php\php.ini

and change following...

并更改以下...

    php_value upload_max_filesize xxxxM //file size
    php_value post_max_size xxxxM
    php_value max_execution_time xxxx
    php_value max_input_time xxxx

put xxxx your desire value 1M = 1mb

把 xxxx 你的欲望值 1M = 1mb

You most restart your server after changing...

您最常在更改后重新启动服务器...

回答by d4nt

You can do this easily using sqlizer.io. Here's a screenshot:

您可以使用sqlizer.io轻松完成此操作。这是一个屏幕截图:

Screenshot of sqlizer.io

sqlizer.io 截图

Just select "Comma Separated Values" for the file type and upload your file. It will analyse the data and generate an SQL script containing an appropriate CREATE TABLE statement, and a lot of INSERT statements.

只需为文件类型选择“逗号分隔值”并上传您的文件。它将分析数据并生成包含适当的 CREATE TABLE 语句和大量 INSERT 语句的 SQL 脚本。

(Disclaimer: I help run SQLizer)

(免责声明:我帮助运行 SQLizer)

回答by Chethiya_K

Use https://csvtosql.comonline CSV to SQL converter tool. Paste your CSV lines and Convert them to SQL queries. Then you can save them in a SQL file or directly run them on SQL console on phpmyadmin

使用https://csvtosql.com在线 CSV 到 SQL 转换器工具。粘贴您的 CSV 行并将它们转换为 SQL 查询。然后你可以将它们保存在一个 SQL 文件中,或者直接在 phpmyadmin 的 SQL 控制台上运行它们

screenshot

截屏