douchun1859 2009-12-23 16:02
浏览 34
已采纳

我该怎么做才能使mysql 100%达到最佳状态?

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.

  • 写回答

7条回答 默认 最新

  • duangong1979 2009-12-23 16:08
    关注

    Some top tips from MySQL Performance tips forge

    Specific Query Performance:

    1. Use EXPLAIN to profile the query execution plan
    2. Use Slow Query Log (always have it on!)
    3. Don't use DISTINCT when you have or could use GROUP BY Insert performance
    4. Batch INSERT and REPLACE
    5. Use LOAD DATA instead of INSERT
    6. LIMIT m,n may not be as fast as it sounds
    7. Don't use ORDER BY RAND() if you have > ~2K records
    8. Use SQL_NO_CACHE when you are SELECTing frequently updated data or large sets of data
    9. Avoid wildcards at the start of LIKE queries
    10. Avoid correlated subqueries and in select and where clause (try to avoid in)

    Scaling Performance Tips:

    1. Use benchmarking
    2. isolate workloads don't let administrative work interfere with customer performance. (ie backups)
    3. Debugging sucks, testing rocks!
    4. 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:

    1. 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
    2. Use multi_query if appropriate to reduce round-trips
    3. Use stored procedures to avoid bandwidth wastage

    OS Performance Tips:

    1. Use proper data partitions 1. For Cluster. Start thinking about Cluster before you need them
    2. Keep the database host as clean as possible. Do you really need a windowing system on that server?
    3. Utilize the strengths of the OS
    4. pare down cron scripts
    5. create a test environment
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么