Langsung ke konten utama

Postingan

Menampilkan postingan dengan label linux

export mysql to csv with command line

First, I can give you the answer for ONE table: The trouble with all these INTO OUTFILE or --tab=tmpfile (and -T/path/to/directory) answers is that it requires running mysqldump on the same server as the MySQL server, and having those access rights. My solution was simply to use mysql (NOT mysqldump) with the -B parameter, inline the SELECT statement with -e, then massage the ASCII output with sed, and wind up with CSV including a header field row: Example: mysql -B -u root -p dbname -e "SELECT * FROM query;" | sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g" > test.csv output: "id","login","password","folder","email" "8","mariana","xxxxxxxxxx","mariana","" "3","squaredesign","xxxxxxxxxxxxxxxxx","squaredesign","mkobylecki@squaredesign.com" "4","miedziak",