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 -
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!