当前位置: 首页 » 无间道三 » 正文

九五至尊

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

万水千山总是情

一 |     (ECNS) -- From Singapore to Vancouver, Mandarin pop stars are drawing crowds abroad, underscoring China’s growing cultural reach. Jackson Wang, Zhou Shen and Silence Wang are among the artists leading the surge in overseas tours.    Chinese promoter CMC Live has signed a two-year partnership with Singapore’s IMC Group Asia to expand shows internationally.        IMC COO Leong Yew Soon said Chinese artists guarantee strong ticket sales in Singapore and Malaysia, while breaking into non-Chinese mainstream markets will take longer.    “Audiences ask if Chinese artists are coming because they know the box office will be stronger,” he said.     CMC Live CEO Hong Di pointed to Wang’s global recognition from his South Korean idol days and English language songs as keys to his success.        He added that language barriers are fading as social media introduces more audiences to Chinese music.    Executives expect Asia’s concert industry to keep rising as new venues open in Singapore, Malaysia and Thailand, while promoters eye Western markets.    (By Helen Mo & intern Xu Wenda)                    。

二 |     

     一键部署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://692khl.pochehaihuandangfenzei.shop/list_byp1/6sgti6r.html

Published on:12:59:10


 
[ 丈母娘看女婿 ]  [ 顺丰 ]  [ 上班这党事 ]  [ 太阳耀斑 ]  [ 朝5晚9 ]  [ 四大名捕 ]

 
 
推荐图文
独立日
推荐资讯
点击排行
v字仇杀队 |  窈窕淑女 |  复仇者联盟 |  你的名字 |  生活大爆炸第六季 |  择天记 |  一闪一闪亮晶晶 |  悠长假期 |  城市猎人
Copyright © 2001-2018 九五至尊 Corporation, All Rights Reserved
九五至尊--河南省综合性门户网站,致力于为河南企业及网民提供信息化服务!   九五至尊地方网站联盟成员   通用网址:九五至尊

西部世界   龙的天空   美丽人生   蓝山球队第一季   纸牌屋   等着我

胡雪岩