I have a server with multiple databases on it. Its actually an instance on AmazonRDS so I do not have access to the my.cnf file. What I am trying to do is a create a log for each database separately that records the queries that were previously ran and possible errors generated by those queries. Is this possible with mysql to have a separate log file for each db/schema?
Update
Im looking for a solution like this, but not for the WHOLE server. https://stackoverflow.com/questions/650238/how-to-show-the-last-queries-executed-on-mysql
Best Answer
I cannot speak in terms of AmazonRDS but here is something generic to try
Did you know that the slow log is a CSV file it you activate it?
If you look at the mysql.slow_log, you see this:
This is no good to you as a CSV file. You can convert it to MyISAM and use it.
Here is what you can do:
Here are the basic steps:
Next, enable logging to
mysql.slow_log
by adding this to/etc/my.cnf
If you still want a text file for slow queries in addition to a table, then use
Now you are probably wondering why I am showing the
mysql.slow_log
table and notmysql.general_log
. Well, here ismysql.general_log
:There is nothing that points a query to the database in
mysql.general_log
.Oh, by the way, you have to set other things to get the
mysql.slow_log
catch everythingThat way, every query and its grandmother gets recorded in
mysql.slow_log
.EPILOGUE
All you need do is run queries against
mysql.slow_log
. For example, to see all queries from themydb
database for today, you would run:Since you are using Amazon RDS, you will have to check the Documentation to see if you can manipulate
mysql.slow_log
to your liking.Here are my past posts in the StackExchange about using
mysql.slow_log
:Nov 18, 2011
: Create a custom log table in MySQLDec 27, 2011
: How to do MySQL User AccountingMar 30, 2012
: MySQL slow log configurationNov 06, 2012
: AWS RDS MySQL / Slow Query Log