
- 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 import the text file, having data on the same line with a separator, into MySQL table?
Actually, we can write the data on the same line in the text file by using a separator. In this case, while importing this text file into MySQL table then we must have to use ‘LINES TERMINATED BY’ option. It can be understood with the help of the following example −
Suppose we are using ‘|’ as the LINE TERMINATOR symbol in a text file as follows −
id,Name,Country,Salary|105,Chum*,Marsh,USA,11000|106,Danny*,Harrison,AUS,12000
Now while importing this text file into MySQL table then we need to mention ‘LINE TERMINATED BY’ option also in the query as follows −
mysql> LOAD DATA LOCAL INFILE 'd:\A.txt' INTO table employee7_tbl FIELDS TERMINATED BY ',' ESCAPED BY '*' LINES TERMINATED BY '|'IGNORE 1 ROWS; Query OK, 2 rows affected (0.05 sec) Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
Now, we can see what has been imported with the help of the following query −
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)
- Related Articles
- How can we import the text file, having some line prefixes, 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 only specific columns from the text file, into MySQL table?
- How can we MySQL LOAD DATA INFILE statement with ‘ENCLOSED BY’ option to import data from text file into MySQL table?
- How can we MySQL LOAD DATA INFILE statement with ‘FIELDS TERMINATED BY’ option to import data from text file into MySQL table?
- How can we export all the data from MySQL table into a text file?
- How can we import data from a text file having names of the columns in first row?
- How can we export all the data from MySQL table into a CSV file?
- How can we export some field(s) from MySQL table into a text file?
- How can we insert data into a MySQL table?
- How MySQL evaluates the blank line between two lines written in the text file while importing that text file into MySQL table?
- How can we upload the changed value, rather than written in a text file, of column(s) while importing that text file into MySQL table?
- What kind of settings can we do to a text file by query while exporting the values from MySQL table into a text file?
- How can we export some field(s) from MySQL table into a CSV file?

Advertisements