Koda
Koda

Reputation: 43

SQL On Server: Saving Query Statements to a File

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?

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.

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"

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

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

Upvotes: 4

Views: 73

Answers (1)

paul
paul

Reputation: 22011

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

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

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

Upvotes: 1

Related Questions