0

How to find the inefficient queries in mysql database ? I want to do performance tuning on my queries , but i coudn't find where my queries are located ? Please suggest me where can i find mysql queries for my tables .

Thanks

Prabhakaran.R

7
  • they are in mysql stored procedures/functions/events/triggers, or most likely passed thru from your source code. programming language. php. what are you using ? Commented Jul 22, 2015 at 3:38
  • possible duplicate of SQL Query - Performance Optimization Commented Jul 22, 2015 at 3:44
  • post any particularly slow ones with schema, we can give it a go :> Commented Jul 22, 2015 at 5:23
  • @DrewPierce to find which one runs slow .. i need to get into logs , enable the slow query logs : set global slow _query_log ='ON' ,set global long_query_time = 1 ; but i cant get through /var/lib/mysql to see my logs .. it says permission denied . what to do ?? Commented Jul 22, 2015 at 6:12
  • talk to the guy who can sudo ? Commented Jul 22, 2015 at 6:15

3 Answers 3

2

You can enable the general log and slow query logs.

Enabling general query log will log all the queries and might be heavy if you have many reads/writes. In slow query log, you can mention a threshold and only queries taking time beyond some time will be logged. Post that, you can manually analyze it or you can use tools provided( Percona has great tools)

Sign up to request clarification or add additional context in comments.

1 Comment

enable the slow query logs : set global slow _query_log ='ON' ,set global long_query_time = 1 ; but i cant get through /var/lib/mysql to see my logs .. it says permission denied . what to do ??
0

Have you analyzed your queries with explain plans? You may be able to find a query that will return the result set you wish that isn't as heavy a load on the query engine. Remember to only select the columns you actually need (try to avoid SELECT *), well planned indexing and to use inner/outer joins in favour of a huge list of WHERE clause filters.

Good luck.

RP

2 Comments

i want to know - how can i find my slow processing queries ? where it is located ?
enable the slow query logs : set global slow _query_log ='ON' ,set global long_query_time = 1 ; but i cant get through /var/lib/mysql to see my logs .. it says permission denied . what to do ??
0

In addition to what the others said, use pt-query-digest (from percona.com) to summarize the slowlog. That will tell you the worst queries.

Performance tuning often involves knowing what indexes to put on tables. My index cookbook is one place to learn how to build an INDEX for a given SELECT.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.