I am learning MySql and need help with ‘INTO FILE’. I have managed to terminate with commas but the last entry in the file also contains a comma which means when imported treats it as a blank entry.
Could someone show me the corret way to use ‘INTO FILE’ by way of an example. I have posted my query if it helps but it is almost certainly incorrect. Many thanks
Select
boxes.custref
From
boxes
Where
boxes.customer = 'demo'
AND department = 'demo'
INTO OUTFILE '/temp/demodept.csv'
FIELDS TERMINATED BY ','
LINES TERMINATED BY ',';
And your last line ends with a comma. Which means your file is telling the engine that the line has terminated, and a new line starts…so yes, there is a blank line at the end of your file.
Why are you terminating your lines with the same delimiter as your fields? Terminate with a line break ('\n'), and then check the outfile for a blank line at the end of the file; if one exists, remove it before importing the file again, and you wont end up with a blank entry.
I have double checked the query in phpmyadmin and this blank entry is only there when i run export function. Do you have example of the correct way to code the into file? Thanks