MySQL SELECT INTO OUTFILE to a different server?

前端 未结 2 1217
悲哀的现实
悲哀的现实 2020-12-18 00:17

I have a shell script on server a. The script spits out a csv file to a local directory. The problem is the database server is on server b. How do I use select * int

相关标签:
2条回答
  • 2020-12-18 00:43

    Use the command below:

    mysql -uusername -ppassword -h DBIP DBNAME -e \
    "SELECT * FROM tablename" > /destinationpath/outputfilename.csv
    
    0 讨论(0)
  • 2020-12-18 00:58

    select into outfile can only create the file on the server, not the client.

    Here's what the manual recommends for your situation:

    If you want to create the resulting file on some client host other than the server host, you cannot use SELECT ... INTO OUTFILE. In that case, you should instead use a command such as mysql -e "SELECT ..." > file_name to generate the file on the client host.

    http://dev.mysql.com/doc/refman/5.1/en/select.html

    0 讨论(0)
提交回复
热议问题