TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Convert CSV files into MySQL insert scripts

41 点作者 d4nt超过 10 年前

19 条评论

pi-rat超过 10 年前
Or just do something like:<p><pre><code> LOAD DATA INFILE &#x27;data.csv&#x27; INTO TABLE mytable FIELDS TERMINATED BY &#x27;,&#x27; ENCLOSED BY &#x27;&quot;&#x27; LINES TERMINATED BY &#x27;\r\n&#x27; IGNORE 1 LINES;</code></pre>
评论 #8236764 未加载
sarciszewski超过 10 年前
In my experience, this is actually not that difficult or novel, but kudos on trying new things. Keep it up :)
评论 #8236855 未加载
评论 #8237181 未加载
mathnode超过 10 年前
I am not putting 1TB+ per table dumps of data into a strangers website what can be done with a bit of sed or a script in ${LANGUAGE}.<p>Loader from Several Nines, is a tool for doing parallel loads of CSV into MySQL and MariaDB <a href="https://github.com/severalnines/loader" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;severalnines&#x2F;loader</a><p>Mydumper is a threaded dump and load tool for MySQL&#x2F;MariaDB. <a href="https://launchpad.net/mydumper" rel="nofollow">https:&#x2F;&#x2F;launchpad.net&#x2F;mydumper</a><p>Tungsten Replicate can do batch load replication into any external datasource <a href="http://docs.continuent.com/tungsten-replicator-3.0/deployment-batchloading.html" rel="nofollow">http:&#x2F;&#x2F;docs.continuent.com&#x2F;tungsten-replicator-3.0&#x2F;deploymen...</a> So long as you have a script for it: <a href="https://code.google.com/p/tungsten-replicator/source/browse/branches/replicator-3.0.0/replicator/samples/scripts/batch/mysql.js" rel="nofollow">https:&#x2F;&#x2F;code.google.com&#x2F;p&#x2F;tungsten-replicator&#x2F;source&#x2F;browse&#x2F;...</a><p>EDIT: A fun extra, <a href="https://mariadb.com/kb/en/mariadb/documentation/storage-engines/connect/connect-table-types/connect-table-types-data-files/#csv-and-fmt-table-types" rel="nofollow">https:&#x2F;&#x2F;mariadb.com&#x2F;kb&#x2F;en&#x2F;mariadb&#x2F;documentation&#x2F;storage-engi...</a>
评论 #8237008 未加载
phpnode超过 10 年前
MySQL already supports loading CSVs directly, why convert them first? <a href="http://dev.mysql.com/doc/refman/5.1/en/load-data.html" rel="nofollow">http:&#x2F;&#x2F;dev.mysql.com&#x2F;doc&#x2F;refman&#x2F;5.1&#x2F;en&#x2F;load-data.html</a>
评论 #8236672 未加载
评论 #8236684 未加载
评论 #8236676 未加载
agildehaus超过 10 年前
This submits to your server. If I have sensitive data, I sure as hell don&#x27;t want that going somewhere where it might be stored.<p>Why isn&#x27;t this just done client-side in Javascript?
评论 #8237105 未加载
评论 #8236845 未加载
评论 #8236745 未加载
评论 #8236705 未加载
eli超过 10 年前
The first python script I ever wrote does csv to SQL: <a href="https://github.com/elidickinson/csv-tools/blob/master/csv2sql.py" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;elidickinson&#x2F;csv-tools&#x2F;blob&#x2F;master&#x2F;csv2sq...</a> It&#x27;s very rough, but I actually still use it on occasion. The Python csv library is quite good. There&#x27;s a lot that can go wrong that LOAD DATA can&#x27;t handle.
NicoJuicy超过 10 年前
I actually have some code (.Net) that loads xml, csv, ... into objects.<p>There is also a visual drawing to help you connect the dots between the properties of the uploaded file vs. the properties of the objects.<p>This way, all information gets loaded into the db from a single import, in the correct table.<p>I could seperate it in a opensource project i suppose, if anyone is interested.
评论 #8236919 未加载
itazula超过 10 年前
I submitted the following file (note the blanks): $ cat testblanks.csv 1997, Ford, E350<p>The following was returned: CREATE TABLE testblanks (Column_1 NUMERIC(32, 16),Column_2 VARCHAR(5) CHARACTER SET utf8,Column_3 VARCHAR(5) CHARACTER SET utf8); INSERT INTO testblanks VALUES (1997,&#x27; Ford&#x27;,&#x27; E350&#x27;);<p>That was in accordance with <a href="http://tools.ietf.org/html/rfc4180" rel="nofollow">http:&#x2F;&#x2F;tools.ietf.org&#x2F;html&#x2F;rfc4180</a><p>Cool!<p>But the CSV format has a lot of &quot;gotchas.&quot; See, for example, <a href="http://discuss.fogcreek.com/joelonsoftware3/default.asp?cmd=show&amp;ixPost=99824&amp;ixReplies=25" rel="nofollow">http:&#x2F;&#x2F;discuss.fogcreek.com&#x2F;joelonsoftware3&#x2F;default.asp?cmd=...</a>. Especially the rant about the Microsoft version of CSV.
评论 #8236789 未加载
vijayr超过 10 年前
Nice idea.<p>Can I suggest another idea? Take JSON files, and convert them into MySQL, postgres etc insert&#x2F;update scripts. There is a need for this. For example, I run this hobby site <a href="http://kivatools.com" rel="nofollow">http:&#x2F;&#x2F;kivatools.com</a> that imports tons of data from kiva.org - their data dumps are in json&#x2F;xml format. so I&#x27;ve a script that refreshes the db every night, with a couple of gigs of data. It would be very useful if there was a service that can take a url (or file), and convert json&#x2F;xml into mysql scripts.
Gonzih超过 10 年前
I think it can be done in few lines of ruby&#x2F;python&#x2F;whatever code. Without submitting sensitive data to remote unknown server. IMHO it would be much better idea to release code as opensource.
sheetjs超过 10 年前
You should be able to do this entire thing in-browser. Going further, leveraging WebSQL or SQL.js, it should be possible to pump the queries into a client-side database and run queries.<p>Shameless plug: I built an in-browser tool to generate SQL queries from Excel XLS&#x2F;XLSX&#x2F;XLSB files: <a href="http://sheetjs.com/sexql/" rel="nofollow">http:&#x2F;&#x2F;sheetjs.com&#x2F;sexql&#x2F;</a><p>Discussion: <a href="https://news.ycombinator.com/item?id=7392665" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7392665</a>
onion2k超过 10 年前
Tried it with a file containing this:<p><pre><code> Field1,Field2,Field3,Int,Float,Quoted This,is,a,12,1.2,&quot;&quot;&quot;file&quot;&quot;&quot; </code></pre> ...and it returned an empty textarea.
quasiben超过 10 年前
This is great! People should have better and faster ways of handling CSV -&gt; DB interactions. We recently added native CSV loading into blaze for MySQL, PostgreSQL, and SQLITE, <a href="https://github.com/ContinuumIO/blaze/blob/master/blaze/data/sql.py#L283" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ContinuumIO&#x2F;blaze&#x2F;blob&#x2F;master&#x2F;blaze&#x2F;data&#x2F;...</a><p>MongoDB is coming soon.
gregcsv超过 10 年前
Here&#x27;s one I made a few years ago:<p><a href="http://utilitymill.com/utility/csv_to_create_table/" rel="nofollow">http:&#x2F;&#x2F;utilitymill.com&#x2F;utility&#x2F;csv_to_create_table&#x2F;</a><p>You just paste the content from excel or a csv.<p>It actually tries to figure out the data types and creates a table for you as well.
stef25超过 10 年前
Tested it out with GeoIPCountryWhois.csv from Maxmind, seems to work ok. However selecting the output is almost impossible, locks up Chrome. This isn&#x27;t your apps fault of course. Usually I use Sequel Pro for this, which allows me to map csv fields to db columns
abluecloud超过 10 年前
I&#x27;ve found phpMyAdmin&#x27;s CSV insert feature has been very useful.<p>Allows for quite a few options.
pessimizer超过 10 年前
<a href="http://neilb.bitbucket.org/csvfix/manual/csvfix16/sql_insert.html" rel="nofollow">http:&#x2F;&#x2F;neilb.bitbucket.org&#x2F;csvfix&#x2F;manual&#x2F;csvfix16&#x2F;sql_insert...</a>
squidmccactus超过 10 年前
So does this work with CSV?
digital-rubber超过 10 年前
What is this for ridiculous product&#x2F; attempt?<p>HACKER news, not noobs-that-cant-do-shit.
评论 #8237270 未加载