
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we MySQL LOAD DATA INFILE statement with ‘FIELDS TERMINATED BY’ option to import data from text file into MySQL table?
‘FIELDS TERMINATED BY’ option should be used when the text file which we want to import into MySQL table is having the values which are separated by a comma(,) or maybe with any other separator like a colon(:), semicolon(;) etc. It can be understood with the help of the following example −
Example
Suppose we are having the following data, separated by a semicolon(;), in the text file ‘A.txt’ which we want to import into a MySQL file −
100;Ram;IND;15000 120;Mohan;IND;18000
Now with the help of the following query by using the option ‘FIELDS SEPARATED BY ‘we can import the data into MySQL table −
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)
- Related Articles
- How can we MySQL LOAD DATA INFILE statement with ‘ENCLOSED BY’ option to import data from text file into MySQL table?
- How can we import data from .txt file into MySQL table?
- How can we import data from .CSV file into MySQL table?
- How can we import the text file, having data on the same line with a separator, into MySQL table?
- How can we export all the data from MySQL table into a text file?
- How can we import only specific columns from the text file, into MySQL table?
- How can we import the text file, having some line prefixes, into MySQL table?
- How can we export all the data from MySQL table into a CSV file?
- How can we insert data into a MySQL table?
- How can we export some field(s) from MySQL table into a text file?
- How should I enable LOAD DATA LOCAL INFILE in my.cnf in MySQL?
- What is MySQL LOAD DATA statement?
- How can we insert data into an existing MySQL table by using PHP script?
- MySQL statement to copy data from one table and insert into another table
- How can we copy data with some condition/s from existing MySQL table?

Advertisements