29

How do I profile a MySQL database. I want to see all the SQL being run against a database.

I know you can do this:

  • set profiling=1;
  • Run your slow query (eg SELECT * FROM messages WHERE fromaddress='xxx';
  • SHOW PROFILES;

But this seem to only apply to stuff run on the command line, I want to see the results from running a website.

shgnInc
  • 2,054
  • 1
  • 23
  • 34
Dan
  • 29,100
  • 43
  • 148
  • 207
  • 1
    Obviously, nothing prevents you from running those queries in a web site. I guess you're asking for a method that doesn't imply modifications in the application code. – Álvaro González Aug 29 '13 at 10:29
  • 2
    ["'SHOW PROFILES' is deprecated and will be removed in a future release. Please use Performance Schema instead."](http://dev.mysql.com/doc/refman/5.7/en/show-profiles.html) – bishop Sep 08 '16 at 16:07

5 Answers5

7

You want the query log - but obviously doing this on a heavy production server could be... unwise.

Tom Ritter
  • 99,986
  • 30
  • 138
  • 174
2

That worked for me on Ubuntu.

Find and open your MySQL configuration file, usually /etc/mysql/my.cnf on Ubuntu. Look for the section that says “Logging and Replication”

# * Logging and Replication
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.

log = /var/log/mysql/mysql.log

or in newer versions of mysql, comment OUT this lines of codes

general_log_file        = /var/log/mysql/mysql.log
general_log             = 1
log_error                = /var/log/mysql/error.log

Just uncomment the log variable to turn on logging. Restart MySQL with this command:

sudo /etc/init.d/mysql restart

Now we’re ready to start monitoring the queries as they come in. Open up a new terminal and run this command to scroll the log file, adjusting the path if necessary.

tail -f /var/log/mysql/mysql.log
Sergey Telshevsky
  • 12,077
  • 6
  • 55
  • 78
Matija
  • 17,604
  • 2
  • 48
  • 43
1

There is a commercial product

http://www.webyog.com/en/

Sergey Telshevsky
  • 12,077
  • 6
  • 55
  • 78
Haim Evgi
  • 123,187
  • 45
  • 217
  • 223
0

You can simply parse the query log in real time. If on linux, you can use tail -f to see the log live

Also, you can try some free software from these guys:

http://hackmysql.com/mysqlsla

Bryan Migliorisi
  • 8,982
  • 4
  • 34
  • 47
0

MySqlAdministrator have some useful build in features (including logs view), but for logs it have to be run on same machine as database

buddy
  • 725
  • 1
  • 6
  • 9