如何将文件的部分内容导入MySQL数据库?
将文件的一部分导入 MySQL 数据库的正确语法是什么?例如,我只想加载第 50 行到第 1000 行。
当前我的 SQL 语句将整个文件导入到数据库中。
LOAD DATA INFILE 'myFile.txt' INTO TABLE myTable (col1, col2) Fields TERMINATED BY '\t' LINES TERMINATED BY '\n'
我想要更有选择性。有什么建议吗?谢谢
What is the correct syntax to import a part of a file into a MySQL database? For instance, I want to only load lines 50 to line 1000.
Currently my SQL statement imports an entire file into the database.
LOAD DATA INFILE 'myFile.txt' INTO TABLE myTable (col1, col2) FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'
I want to be more selective. Any suggestions? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
LOAD DATA INFILE
只允许您跳过文件开头的行(例如IGNORE 49 LINES
),但它将导入所有行直到文件末尾。请参阅LOAD DATA INFILE
语法 了解详情。LOAD DATA INFILE
only alows you to skip lines at the beginning of the file (by saying e.g.IGNORE 49 LINES
), but it will import all lines until the end of the file. SeeLOAD DATA INFILE
Syntax for details.head -c 1000 myFile.txt | head -c 1000 myFile.txt | head -c 1000 myFile.txt | head -c 1000 myFile.txt tail -n 950 会给出 50-1000 行。我建议将预处理阶段与数据加载分开
head -c 1000 myFile.txt | tail -n 950
would give the 50-1000 lines. I'd recommend separating the pre-processing stage from dataload