ghosh123 has asked for the wisdom of the Perl Monks concerning the following question:

My application uses MySQL to store data. Is there any module or script in perl which I can use to tune the mysql queries, which are being run frequently, when I am running the application to know the cost of each query and tune them to reduce the cost. Please help.

  • Comment on perl module/script to tune MySQL queries

Replies are listed 'Best First'.
Re: perl module/script to tune MySQL queries
by McA (Priest) on Aug 12, 2013 at 11:26 UTC
Re: perl module/script to tune MySQL queries
by McA (Priest) on Aug 12, 2013 at 16:02 UTC


    some additions. The company Percona* ( does provide some MySQL related tools which can also be used against a non-percona MySQL server. These tools are bundled under the name "Percona Toolkit for MySQL".

    How does this fit here? This toolkit is written in perl, it's open source and provided with a GNU v2 license.

    One script of that is pt-query-digest which aggregates informations from the slow query log. In newer MySQL versions you can even log every statement, so that you get an overview over all statements over time. As far as I know the script or a companion script gives advice how to improve the statements found.

    Probably worth a try. (@Voronich: Something for you?)

    Best regards

    * That is no advertisment from my side

Re: perl module/script to tune MySQL queries
by sundialsvc4 (Abbot) on Aug 13, 2013 at 04:10 UTC

    The EXPLAIN verb can be used to show you the “execution plan” of any SQL statement ... this being the actual sequence of low-level operations that the query engine will carry out in order to do what the query says to do.   It is often the case that “there’s more than one way to do it,” but that one of them will be noticeably better than the others.

    You can obtain slight speedups by “preparing a statement-handle” once, then using it to execute the same query multiple times, changing the set of parameters that you give it each time.

    How many queries-per-second are you running, and what sort of queries are they?   Are the tables InnoDB?   Transactions?