Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is a part of my query

SELECT * INTO OUTFILE 'Target_File_Name' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '' FROM (SELECT 'Start time','Calling no','Called no','Calltype','Cust. name','Total Dur.','Call stat' UNION (SELECT CDR_StartDateTime,CDR_A_Number ,(CASE CDR_B_Number WHEN 0 THEN '' ELSE (CASE CDR_CallTypeWHEN 1 THEN CONCAT('011',CDR_B_Number) ELSE CONCAT('1',CDR_B_Number) END) END ),CDR_CallType_Name ,CDR_CustomerName ,(CASE WHEN CDR_TotalDuration>0 THEN ROUND(CDR_TotalDuration/60,1) ELSE 0.00 END),CDR_CallStat  FROM   tlb_cdrdetails_4   FORCE INDEX(Index_CallStatus) WHERE CDR_StartDateTime >= CAST('2012-04-01 00:00' AS DATETIME) AND CDR_StartDateTime <= CAST('2012-04-30 23:59:59' AS DATETIME) AND CDR_CallStat IN (42, 52)  AND CDR_CustomerID IN (123,1000,1001) AND CDR_CarrierID IN (114,1039,115))) tbl

it fetches some 80 lac records.Its causing Lost connection to Mysql during query error.Is the network speed an issue while downloading huge amount of data

share|improve this question

8 million rows? - network speed will determine how long it takes to download the rows, but as to why you are losing connection, you'd have to dig deeper to see if you have a timeout setting?

share|improve this answer

As you are facing issue in generating the CSV.

SELECT * INTO OUTFILE 'D:/CrossStatV3.3/Download/TempFiles//Call-Details-Report-04-01-2012_06-01-12-09-23-22.csv'........

Once i also faced the same issue i was generating a csv whose size was approximately supposed to 17GB.I found a work around for that

why not use mysqldump which is more powerful and fast.

for generating csv using mysqldump you can do like this

mysqldump -uuser -ppassword --tab="Path where we need to create the CSV" --fields-terminated-by="\t"  --fields-enclosed-by="'" --lines-terminated-by="\n" DB_Name TableName 

this will create the TableName.txt file and TableName.sql files at the location as you specified with --tab option where TableName.txt is your CSV you can rename it as TableName.csv.

Note : use the (--tab="PATH") path where the mysql has write permissions.

for various other options of mysqldump.

please see..

mysqldump --help
share|improve this answer
Well thnks for your reply....i have updated my actual query..can u tell me how to rewrite my query using mysqldump – Jay Jun 4 '12 at 9:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.