write results of sql query to a file in mysql

前端 未结 5 983
心在旅途
心在旅途 2021-02-01 01:44

I\'m trying to write the results of a query to a file using mysql. I\'ve seen some information on the outfile construct in a few places but it seems that this only writes the fi

5条回答
  •  余生分开走
    2021-02-01 01:59

    This is dependent on the SQL client you're using to interact with the database. For example, you could use the mysql command line interface in conjunction with the "tee" operator to output to a local file:

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

    tee [file_name], \T [file_name] 
    

    Execute the command above before executing the SQL and the result of the query will be output to the file.

    Specifically for MySQL Workbench, here's an article on Execute Query to Text Output. Although I don't see any documentation, there are indications that there should be also be an "Export" option under Query, though that is almost certainly version dependent.

提交回复
热议问题