V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
0x0208v0
V2EX  ›  程序员

请问各位有没有珍藏的 MySQL5.7 优化的配置文件?可否分享?能在 700MB 内存云机器跑的那种。我搜了些资料,凑了个配置放帖子里了,求帮忙看看

  •  
  •   0x0208v0 · 14 天前 · 486 次点击

    实测占用 200 ~ 300MB 之间,不知道还有没有更优化的配置。。。

    MySQL 这个玩意儿,应该有很多黑魔法的吧?

    要不然市面上那些 500MB 内存的小 VPS ,或者什么网站空间是怎么部署的?

    配置文件内容如下:

    
    #################################################
    # 参考链接:
    # https://stackoverflow.com/questions/60244889/how-to-decrease-mysql-container-memory-usage
    # https://github.com/alexanderkoller/low-memory-mysql
    #################################################
    
    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
    
    [mysqld]
    #
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    skip-host-cache
    skip-name-resolve
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    secure-file-priv=/var/lib/mysql-files
    user=mysql
    
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    
    
    #### These optimize the memory use of MySQL
    #### http://www.tocker.ca/2014/03/10/configuring-mysql-to-use-minimal-memory.html
    innodb_buffer_pool_size=5M
    innodb_log_buffer_size=256K
    query_cache_size=0
    max_connections=10
    key_buffer_size=8
    thread_cache_size=0
    host_cache_size=0
    innodb_ft_cache_size=1600000
    innodb_ft_total_cache_size=32000000
    
    # per thread or per operation settings
    thread_stack=131072
    sort_buffer_size=32K
    read_buffer_size=8200
    read_rnd_buffer_size=8200
    max_heap_table_size=16K
    tmp_table_size=1K
    bulk_insert_buffer_size=0
    join_buffer_size=128
    net_buffer_length=1K
    innodb_sort_buffer_size=64K
    
    #settings that relate to the binary log (if enabled)
    binlog_cache_size=4K
    binlog_stmt_cache_size=4K
    
    #### from https://mariadb.com/de/node/579
    performance_schema = off
    
    
    4 条回复
    0x0208v0
        1
    0x0208v0  
    OP
       14 天前
    这是 docker-composel.yaml 文件,也限制了内存
    ```
    version: '3'
    services:
    mysql:
    image: mysql:5
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_bin --default-authentication-plugin=mysql_native_password
    volumes:
    - ./mysql_data:/var/lib/mysql
    - ./mysql.cnf:/etc/mysql/conf.d/my.cnf
    environment:
    MYSQL_ROOT_PASSWORD: Y3Zv5l7ZJFiC
    ports:
    - 3306:3306
    ulimits:
    nproc: 65535
    nofile:
    soft: 20000
    hard: 40000
    deploy:
    resources:
    limits:
    cpus: '0.50'
    memory: 500M
    reservations:
    cpus: '0.25'
    memory: 200M

    ```
    ShallowAi
        2
    ShallowAi  
       14 天前 via Android
    1. 关闭或限制 binlog 大小
    2. 使用 mariadb 替代,实测容器环境下,版本 11.3.2 ,内存占用量 63MB 左右,在旧版本 11.1.2 有一定连接数的情况下占用 205MB 左右
    0x0208v0
        3
    0x0208v0  
    OP
       13 天前
    @ShallowAi 谢谢大佬,我试试
    czhh
        4
    czhh  
       13 天前
    蹲一下|・ω・`)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1017 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:14 · PVG 03:14 · LAX 12:14 · JFK 15:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.