
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Import Text File Data 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)
Advertisements