SQL On Server:将查询语句保存到文件

时间:2021-02-27 16:00:09

What I am trying to do: Save the exact queries that MySQL is using to populate data on my website. For this I want to save the ex: 'SELECT * FROM Table WHERE X > 2' that is requested from my database into a text file on the server. To avoid the "Why do you need this?" question, a project for a databases class is asking me to research exactly how a database is gathering data and what better place to learn that than my own website?

我要做的是:保存MySQL用于填充我网站上的数据的确切查询。为此,我想将ex:'SELECT * FROM Table WHERE X> 2'保存到服务器上的文本文件中。为了避免“你为什么需要这个?”问题,数据库类的项目要求我确切地研究数据库如何收集数据以及比我自己的网站更好的学习内容?

What I have tried: I looked into the SPOOL command, but that is only for Oracle systems from what I have gathered. Looking in to the Tee command, I could append query results to a file.

我尝试过:我查看了SPOOL命令,但这仅适用于我收集的Oracle系统。查看Tee命令,我可以将查询结果附加到文件中。

Why my attempts have not been successful: The solution cannot be through SQL queries as I am not having exact control of how the database is filled. The database created from a connector called the IMDB-Connector and is populated when I pass a query into the API. With this implementation I am looking for something along the lines of an "Enable Logging of Queries in fill X.log"

为什么我的尝试没有成功:解决方案不能通过SQL查询,因为我无法准确控制数据库的填充方式。数据库是从名为IMDB-Connector的连接器创建的,当我将查询传递给API时会填充该数据库。通过这个实现,我正在寻找一些“在填充X.log中启用查询记录”的内容

TL;DR: Is there a way to log the queries used to access a certain MySQL database hosted on a server?

TL; DR:有没有办法记录用于访问服务器上托管的某个MySQL数据库的查询?

Long time reader of * but first time querying the human database; will edit the question if not adequately explained.

*的长时间读者,但第一次查询人类数据库;如果没有充分解释,将编辑问题。

1 个解决方案

#1


1  

You can use SET profiling = 1; to turn the mySql profiler on

您可以使用SET profiling = 1;打开mySql探查器

Then you can use SHOW PROFILES to list recently run SQL Statements

然后,您可以使用SHOW PROFILES列出最近运行的SQL语句

http://dev.mysql.com/doc/refman/5.5/en/show-profile.html

#1


1  

You can use SET profiling = 1; to turn the mySql profiler on

您可以使用SET profiling = 1;打开mySql探查器

Then you can use SHOW PROFILES to list recently run SQL Statements

然后,您可以使用SHOW PROFILES列出最近运行的SQL语句

http://dev.mysql.com/doc/refman/5.5/en/show-profile.html