1

Possible Duplicate:
How to enable MySQL Query Log?

Is there a way to track every SQL query in MySQL?

Im using Doctrine ORM to build entities and fetch them from database, and would like to see what queries is Doctrine producing. So when I refresh a webpage that uses Doctrine ORM to fetch some data from database, where could I see queries executed in database?

Is this possible?

Community
  • 1
  • 1
otporan
  • 1,345
  • 2
  • 12
  • 29

2 Answers2

1

Enable MySQL's general query log:

The general query log is a general record of what mysqld is doing. The server writes information to this log when clients connect or disconnect, and it logs each SQL statement received from clients. The general query log can be very useful when you suspect an error in a client and want to know exactly what the client sent to mysqld.

Inside MySQL

set global general_log = 1;
set global log_output = 'table' /* so we can query it*/

select * from general_log       /* to select */

truncate general_log            /*if you got to much data*/

set global general_log = 0      /*to turn it off again*/
Johan
  • 74,508
  • 24
  • 191
  • 319
eggyal
  • 122,705
  • 18
  • 212
  • 237
0

Let this application decide if you want queries logged and log queries on MySQLs side if you want all queries logged.

Doctrine has a builtin logger interface and a demo logger in the package. From http://docs.doctrine-project.org/en/2.0.x/reference/configuration.html#sql-logger-optional :

<?php
$config->setSQLLogger($logger);
$config->getSQLLogger();

Gets or sets the logger to use for logging all SQL statements executed by Doctrine. The logger class must implement the Doctrine\DBAL\Logging\SQLLogger interface. A simple default implementation that logs to the standard output using echo and var_dump can be found at Doctrine\DBAL\Logging\EchoSQLLogger.`

Johan
  • 74,508
  • 24
  • 191
  • 319
Clarence
  • 2,944
  • 18
  • 16