Mysql export resultset as CSV from remote server

My application runs on server 1, and the database is on server 2. I want to receive the output of the selection request as CSV to server 1, that is, to my application server. How can i achieve this. The choice in outfile will not help, because it is deleted only on the local server, so if I run the query on the database server, it will create a file on it not the application server. The mysql -e option also provides help because it does not reset the CSV. Can anyone suggest how to directly create a file locally as CSV from a remote server? Thanks.

+4
source share
1 answer

Can you use outfile and then ftp file to localhost or transfer the result of a regular request to some sed / awk to convert it to csv?

What I found: mysql -umysqlusername -pmysqlpass databasename -B -e "select * from \`tablename\`;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > mysql_exported_table.csv mysql -umysqlusername -pmysqlpass databasename -B -e "select * from \`tablename\`;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > mysql_exported_table.csv

In addition, we move on to solving the ftp solution.

+6
source

Source: https://habr.com/ru/post/1483556/


All Articles