国内我的网站主页 > 我的网站国内 >
摘要:幸福魔方...

healer

网站数据库优化:MySQL调优和缓存策略_我的网站

国产凌凌漆

一 |     British actress Emilia Clarke has revealed that she is missing "quite a bit" of her brain after she battled two aneurysms while shooting 'Game of Thrones'.,"The amount of my brain that is no longer usable — it's remarkable that I am able to speak, sometimes articulately, and live my life completely normally with absolutely no repercussions," Clarke told BBC One's Sunday Morning.,According to her, she is lucky to be a part of a "really, really, really small minority of people that can survive that".,One of the aneurysms the actress suffered was in 2011, shortly after the first season of 'Game of Thrones' wrapped up filming. Clarke had a stroke and a subarachnoid hemorrhage because of the aneurysm, and even suffered from temporary aphasia - a speech disorder.,In 2019, she admitted that she had even asked medical staff to let her die in 2011, believing the brain damage would ruin her acting career. However, Clarke managed to recover and continued working even after undergoing new surgery in 2013 for another aneurysm that was about to "pop".,The actress surged to worldwide fame after playing the role of Daenerys Targaryen in HBO hit 'Game of Thrones'. She also appeared in 'Terminator Genisys', 'Me Before You', and 'Solo: A Star Wars Story'. Among her upcoming projects are the animated movie 'The Amazing Maurice' and Marvel's TV show 'Secret Invasion'.。    

     一键部署OpenClaw        网站慢,很多时候不是带宽不够,而是数据库查询慢。优化MySQL其实就两件事:加索引和用缓存。    先说索引。

二 | 没索引的查询就是全表扫描,10万条数据能查出你服务器CPU飙到100%。

三 | 加了索引,查询速度能提升百倍。    -- MySQL索引优化示例    -- 查看慢查询(找出需要优化的SQL)    SELECT * FROM mysql.slow_log    WHERE start_time > NOW() - INTERVAL 1 DAY    ORDER BY query_time DESC LIMIT 10;    -- 用EXPLAIN分析查询计划    EXPLAIN SELECT * FROM articles    WHERE category_id = 5 AND status = 1    ORDER BY created_at DESC LIMIT 20;    -- 如果type是ALL(全表扫描),就需要加索引    CREATE INDEX idx_category_status_time    ON articles(category_id, status, created_at);    -- 复合索引遵循最左前缀原则    -- 即:查询条件从左到右依次命中索引    再说缓存。领用最多的场景是Redis缓存。把查询结果存到Redis里,下次查询直接从Redis取,不用查数据库。

四 |     # Redis缓存示例(PHP + Redis)    // 先查缓存    $redis = new Redis();    $redis->connect('127.0.0.1', 6379);    $cacheKey = 'article_list_page_' . $page;    $cached = $redis->get($cacheKey);    if ($cached) {    // 缓存命中,直接返回    echo $cached;    } else {    // 缓存未命中,查数据库    $articles = $pdo->query("SELECT * FROM articles ORDER BY id DESC LIMIT 20")->fetchAll();    $html = renderArticles($articles);    // 存入缓存,过期10分钟    $redis->setex($cacheKey, 600, $html);    echo $html;    }    MySQL本身也有查询缓存,在my.cnf里开启就行。但注意,数据更新后缓存不会立即失效,对实时性要求高的场景不适合。

五 |     # MySQL查询缓存配置(my.cnf)    query_cache_type = 1    query_cache_size = 64M    query_cache_limit = 2M    # InnoDB缓冲池大小(一般设为内存的70%)    innodb_buffer_pool_size = 2G    innodb_log_file_size = 256M    最后,定期清理数据库碎片和日志。数据量大了,碎片会导致查询变慢。

六 | 每月跑一次OPTIMIZE TABLE就能解决。

        
    

申请创业报道,分享创业好点子。点击此处,共同探讨创业新机遇!。

Current article:http://9rc6.yaoyaotoutuanmieshaideizun.buzz/4yrln3/20260826/1695448.html

Published on:00:00:00