Recently I've been doing quite a big project with php + mysql. And now I'm concerned about my mysql. What should I do to make my mysql as optimal as possible? Tell everything you know, I'll be really very grateful.
Second question, I use one mysql query per page load which takes information from mysql. It's quite a big query, because I take information from a few tables with a join. Maybe I should do something else?
Thank you.
Some top tips from MySQL Performance tips forge
Specific Query Performance:
- Use EXPLAIN to profile the query
execution plan
- Use Slow Query Log (always have it
on!)
- Don't use DISTINCT when you have or
could use GROUP BY Insert
performance
- Batch INSERT and REPLACE
- Use LOAD DATA instead of INSERT
- LIMIT m,n may not be as fast as it
sounds
- Don't use ORDER BY RAND() if you
have > ~2K records
- Use SQL_NO_CACHE when you are
SELECTing frequently updated data or
large sets of data
- Avoid wildcards at the start of LIKE
queries
- Avoid correlated subqueries and in
select and where clause (try to
avoid in)
Scaling Performance Tips:
- Use benchmarking
- isolate workloads don't let administrative work interfere with customer performance. (ie backups)
- Debugging sucks, testing rocks!
- As your data grows, indexing may change (cardinality and selectivity change). Structuring may want to change. Make your schema as modular as your code. Make your code able to scale. Plan and embrace change, and get developers to do the same.
Network Performance Tips:
- Minimize traffic by fetching only what you need.
1. Paging/chunked data retrieval to limit
2. Don't use SELECT *
3. Be wary of lots of small quick queries if a longer query can be more efficient
- Use multi_query if appropriate to reduce round-trips
- Use stored procedures to avoid bandwidth wastage
OS Performance Tips:
- Use proper data partitions
1. For Cluster. Start thinking about Cluster before you need them
- Keep the database host as clean as possible. Do you really need a windowing system on that server?
- Utilize the strengths of the OS
- pare down cron scripts
- create a test environment
Learn to use the explain tool.