PHP Classes

Using global variables instead

Recommend this page to a friend!

      PHP Classes blog  >  Find MySQL Slow Queri...  >  All threads  >  Using global variables instead  >  (Un) Subscribe thread alerts  
Subject:Using global variables instead
Summary:set global slow_query_log=ON;
Messages:4
Author:Erik Liljencrantz
Date:2022-10-13 10:21:34
Update:2022-10-15 05:06:52
 

  1. Using global variables instead   Reply   Report abuse  
Picture of Erik Liljencrantz Erik Liljencrantz - 2022-10-13 23:20:43
Using the server global variables may be easier than restarting the DB server. Also adjusting what is considered slow, i.e. setting the long_query_time variable.

Start mysql on command line, then check variables:
show global variables like "%slow%";
show global variables like "%long%";

Enable log, above 0.5 second:
set global slow_query_log=ON;
set long_query_time=0.5;

For production You can still keep it turned on, but raise "what is considered slow" and limit logging rate:
set long_query_time=2;
set log_slow_rate_limit=2;

And of course, adjust settings in my.cnf / server.cnf or similar for good values after any restart.

  2. Re: Using global variables instead   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2022-10-14 05:15:15 - In reply to message 1 from Erik Liljencrantz
Hello Erik,

Good points. Avoiding restarting a server is a good idea to prevent application downtime.

Raising the long_query_time is an excellent idea to start optimizing the queries that may be the slowest.

This podcast episode will continue with parts we are editing to publish soon, probably next week.

I suggest you keep following and giving feedback to help improve the techniques presented in the podcast.

I am sure all PHP developers reading this will appreciate it.

Thank you for your participation.

  3. Re: Using global variables instead   Reply   Report abuse  
Picture of Erik Liljencrantz Erik Liljencrantz - 2022-10-14 15:56:30 - In reply to message 1 from Erik Liljencrantz
I missed "global" as in "set global" in some of the lines. i.e.:

set global slow_query_log=ON;
set global long_query_time=0.5;

set global long_query_time=2;
set global log_slow_rate_limit=2;

  4. Re: Using global variables instead   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2022-10-15 05:06:52 - In reply to message 3 from Erik Liljencrantz
Great. Thank you again.