Tuesday, 18 August 2015

How to fetch data from database and write into file in mysql



1) Normally we are selecting record from a table :
  select *from student
O/P: 100 chinmay kumar tripathy(In database)

2) If we have to write the record in a file then :
select * into outfile  'E:/chinmay/temp.txt' from student
O/P: 100 chinmay kumar tripathy(In file location E:/chinmay/temp.txt)

3) If we have to write the file in specific format then:

select * into outfile  'E:/chinmay/temp.txt 'FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n' from student
O/P: 100,"chinmay","kumar","tripathy" (In file location E:/chinmay/temp.txt)