我想加载一个如下所示的文本文件:
11 aaa
22 bbb
# comment
33 ccc
44 bbb
# comment
55 eee
我正在使用这个命令
LOAD DATA LOCAL INFILE '/d:\test.txt'
INTO TABLE foo
COLUMNS TERMINATED BY ' '
IGNORE 1 LINES
(@'#')
我想用 # 跳过行的星号
最佳答案
我认为忽略 n 行并不像你期望的那样工作。 文档说
If all the lines you want to read in have a common prefix that you want to ignore, you can use LINES STARTING BY 'prefix_string' to skip over the prefix, and anything before it. If a line does not include the prefix, the entire line is skipped. Suppose that you issue the following statement:
LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test
FIELDS TERMINATED BY ',' LINES STARTING BY 'xxx';
If the data file looks like this:
xxx"abc",1
something xxx"def",2
"ghi",3
The resulting rows will be ("abc",1) and ("def",2). The third row in the file is skipped because it does not contain the prefix.
The IGNORE number LINES option can be used to ignore lines at the start of the file. For example, you can use IGNORE 1 LINES to skip over an initial header line containing column names:
LOAD DATA INFILE '/tmp/test.txt' INTO TABLE test IGNORE 1 LINES;
我认为最好的办法是在加载文件之前清除输入文本。
关于Mysql 跳过 LOAD DATA INFILE 中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27927940/