LOADDATALOCALINFIL"/> LOADDATALOCALINFIL">

Home >Database >Mysql Tutorial >How can we import data from a text file into a MySQL table using MySQL LOAD DATA INFILE statement with 'FIELDS TERMINATED BY' option?

How can we import data from a text file into a MySQL table using MySQL LOAD DATA INFILE statement with 'FIELDS TERMINATED BY' option?

WBOY
WBOYforward
2023-09-02 11:13:061381browse

我们如何使用带有“FIELDS TERMINATED BY”选项的 MySQL LOAD DATA INFILE 语句将数据从文本文件导入到 MySQL 表中?

When we want to import a text file into a MySQL table with values ​​separated by comma (,) or any other delimiter like colon (:), we should use "FIELDS TERMINATED BY" ” option, can be understood through the following example -

Example

Suppose we have the following data, separated by semicolon (;), in a text file that we want to import into a MySQL file "A.txt" -

100;Ram;IND;15000
120;Mohan;IND;18000

Now with the help of the following query, we can import the data into the MySQL table by using the option "FIELDS SEPARATED BY" -

mysql> LOAD DATA LOCAL INFILE 'd:\A.txt' INTO table employee12_tbl FIELDS TERMINATED BY ';';
Query OK, 2 rows affected (0.04 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0

mysql> Select * from employee12_tbl;
+------+----------------+----------+--------+
| Id   | Name           | Country  | Salary |
+------+----------------+----------+--------+
| 100  | Ram            | IND      |  15000 |
| 120  | Mohan          | IND      |  18000 |
+------+----------------+----------+--------+
2 rows in set (0.00 sec)

The above is the detailed content of How can we import data from a text file into a MySQL table using MySQL LOAD DATA INFILE statement with 'FIELDS TERMINATED BY' option?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete