mysql tips - export csv file from MYSQL database in remote server
1. Export csv file in client server directly This is the situation that I think most beginners will have for doing development or backup of the mysql database. You have a remote mysql server to hold the data, and a local client server to develope. As solution 2 provided by MYSQL official csv export solution will export the file only on the database server (here is on remote server), that is not what we want here. mysql -h hostname -u user -p'password' -P port dbname -e "SELECT * FROM tablename WHERE Date<='2013-07-14';" | sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g" > tablename .csv Using variables and in shell script (which easily cause problems): mysql -h $hostname -u $user -p $pass -P $port $dbname -e "SELECT * FROM $tablename WHERE Date<= '$oldDate'; " | sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g" > tablename .csv For the sed...