How can I have MySQL write outfiles as a different user?

后端 未结 4 1513
Happy的楠姐
Happy的楠姐 2021-02-07 20:46

I\'m working with a MySQL query that writes into an outfile. I run this query once every day or two and so I want to be able to remove the outfile without having to resort to s

4条回答
  •  借酒劲吻你
    2021-02-07 21:14

    Not using the "SELECT...INTO OUTFILE" syntax, no.

    You need to run the query (ie client) as another user, and redirect the output. For example, edit your crontab to run the following command whenever you want:

    mysql db_schema -e 'SELECT col,... FROM table' > /tmp/outfile.txt
    

    That will create /tmp/outfile.txt as the user who's crontab you've added the command to.

提交回复
热议问题