CyberKeeda In Social Media

Bash - Insert data in mysql table from a file using LOAD DATA LOCAL INFILE command.













As every Linux operator loves text file, a text file is enough to process anything within linux using commands.

Today, we will use the power of BASH to insert data into MYSQL table using LOAD DATA LOCAL INFILE commnad from a local text file.


Here i have some data stored into a file named as myfile.txt

Database name - mydb
Table name      - mytable
filename          - myfile.txt


[root@cyberkeeda ~]# mysql -uYOUR_USERNAME -pYOUR_PASS -D mydb -e "load data local infile '/tmp/myfile.txt' into table mytable fields terminated by ',' lines terminated by '\n'"


Remember for windows based system we have to add  \r  along with \n


#       mysql -uYOUR_USERNAME -pYOUR_PASS -D mydb -e "load data local infile '/tmp/myfile.txt' into table mytable fields terminated by ',' lines terminated by '\r\n'"





No comments:

Post a Comment

Designed By Jackuna