实际上,我们可以使用分隔符将数据写在文本文件的同一行上。在这种情况下,将这个文本文件导入MySQL表时,我们必须使用'LINES TERMINATED BY'选项。通过以下示例可以理解-
假设我们使用“ |” 作为文本文件中的行终止符,如下所示:
id,Name,Country,Salary|105,Chum*,Marsh,USA,11000|106,Danny*,Harrison,AUS,12000
现在,当将此文本文件导入MySQL表时,我们还需要在查询中提及“ LINE TERMINATED BY”选项,如下所示:
mysql> LOAD DATA LOCAL INFILE 'd:\A.txt' INTO table employee7_tbl FIELDS TERMINATED BY ',' ESCAPED BY '*' LINES TERMINATED BY '|'IGNORE 1 ROWS; Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
现在,我们可以在以下查询的帮助下查看已导入的内容:
mysql> Select * from employee7_tbl; +------+----------------+----------+--------+ | Id | Name | Country | Salary | +------+----------------+----------+--------+ | 105 | Chum,Marsh | USA | 11000 | | 106 | Danny,Harrison | AUS | 12000 | +------+----------------+----------+--------+ 2 rows in set (0.00 sec)