Please enable JS

Monitor All MySQL Queries

Search all MySQL queries for specific pattern.
July 15/Brian Young/Drupal 7Software
Grep mysql log

I needed to debug some Drupal database queries generated by the Search API DB module.

You can configure MySQL to dump every query to a log file. You can then use tail -f and grep --line-buffered to narrow the output down to a specific search pattern.

Example

log into MySQL and run the following:

  1. SET GLOBAL general_log = 'ON';
  2. SHOW VARIABLES LIKE "general_log%";
  3. exit;

I'm going to assume the path to your general_log_file is: /var/lib/mysql/usb-dev.log.

Grep the results of tail by running the following from your terminal:

  1. sudo tail -f /var/lib/mysql/usb-dev.log | grep --line-buffered sometestpattern

Leave the terminal window open and start browsing your site. When a query matches your search pattern, you should see that line printed to the terminal.



RELATED POSTS


Comments/ 0


LEAVE A COMMENT

(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.
But why?

My random thoughts and documentation on the various hardware and software projects that occupy my day-to-day. My only hope is that other people can benefit from my notes.

Recent posts
Categories