如何读取此文本文件并插入MySQL? [英] How do I read this text file and Insert into MySQL?
本文介绍了如何读取此文本文件并插入MySQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例
用户ID用户名
U456 Mathew
U457 Leon
U458 Cris
U459 Yancy
U460 Jane
等等,最多500k。 p>
我需要读取这个文本文件,并以两列,例如用户ID和用户名插入MySQL。我如何在PHP中这样做?
解决方案
示例:
:
例如:
C:\\path\to\file.txt
$ b b
看起来像:
C:\\\\path\\to\\\ \\file.txt
以下是查询:
LOAD DATA INFILE'/path/to/sample.txt'
pre>
INTO TABLE`database_name`.`table_name`
FIELDS TERMINATED BY','
LINES TERMINATED BY'\r\\\
'
IGNORE 1 LINES
(
user_id,user_name
)
sample
user id User Name U456 Mathew U457 Leon U458 Cris U459 Yancy U460 Jane
and so on up to 500k.
I need to read this text file and insert to MySQL in two columns say User ID and User Name. How do I do this in PHP?
解决方案Example:
NOTE: if you run this from Windows you need to escape the forward slashes in the file path.
EXAMPLE:
C:\\path\to\file.txt
Looks like:
C:\\\\path\\to\\file.txt
Here is the query:
LOAD DATA INFILE '/path/to/sample.txt' INTO TABLE `database_name`.`table_name` FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 LINES ( user_id, user_name )
这篇关于如何读取此文本文件并插入MySQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文