› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
R18
0.06D
V2EX  ›  MySQL

Mysql 内存占用过高 有没有办法优化

  •  
  •   R18 · Feb 26, 2018 · 9560 views
    This topic created in 3175 days ago, the information mentioned may be changed or developed.

    htop Snipaste_2018-02-26_09-09-19.png

    my.cnf

    [client]
    #password       = your_password
    port            = 3306
    socket          = /tmp/mysql.sock
    
    [mysqld]
    port            = 3306
    socket          = /tmp/mysql.sock
    datadir = /data/mysql/var
    skip-external-locking
    key_buffer_size = 256M
    max_allowed_packet = 40M #默认为 1M ( 2016-09-20 09:59 )
    table_open_cache = 1024
    sort_buffer_size = 4M
    net_buffer_length = 8K
    read_buffer_size = 4M
    read_rnd_buffer_size = 512K
    myisam_sort_buffer_size = 64M
    thread_cache_size = 128
    query_cache_size = 128M
    tmp_table_size = 128M
    
    #skip-networking
    max_connections = 500
    max_connect_errors = 100
    open_files_limit = 65535
    
    log-bin=mysql-bin
    binlog_format=mixed
    server-id       = 1
    expire_logs_days = 10
    
    default_storage_engine = InnoDB
    innodb_data_home_dir = /data/mysql/var
    innodb_data_file_path = ibdata1:10M:autoextend
    innodb_log_group_home_dir = /data/mysql/var
    innodb_buffer_pool_size = 1024M
    innodb_additional_mem_pool_size = 2M
    innodb_log_file_size = 256M
    innodb_log_buffer_size = 8M
    innodb_flush_log_at_trx_commit = 1
    innodb_lock_wait_timeout = 50
    
    [mysqldump]
    quick
    max_allowed_packet = 25M
    
    [mysql]
    no-auto-rehash
    
    [myisamchk]
    key_buffer_size = 256M
    sort_buffer_size = 4M
    read_buffer = 2M
    write_buffer = 2M
    
    [mysqlhotcopy]
    interactive-timeout
    
    11 replies  •  2019-10-25 00:09:37 +08:00
    msg7086
    msg7086
    Feb 26, 2018❤️1
    1
    内存占用 2.1%,我觉得还好啊?
    R18
    R18
    OP
    Feb 26, 2018
    2
    @msg7086 他有很多个 2.1% 啊
    simple2025
    simple2025
    Feb 26, 2018 via iPhone❤️1
    3
    htop 的 bug 你用 top 看
    msg7086
    msg7086
    Feb 26, 2018❤️1
    4
    很多个 2.1%也是 2.1%啊,又不会加起来……
    你先切成树状图看看,MySQL 那么多都是线程啊,内存是线程间共享的好么。
    suconghou
    suconghou
    Feb 26, 2018❤️1
    6
    @chenqh @R18 并不是 Bug 这里显示的是线程,mysql 是多线程的。在 htop 里使用 H 可以切换是否以线程方式显示。
    my101du
    my101du
    Feb 26, 2018❤️1
    7
    根据这篇 http://seanlook.com/2017/10/13/mysql-table_open_cache_file_limits/ ,可能使用了预分配内存。

    经测试,我在本地开发环境中使用

    performance_schema_max_table_instances=400
    table_definition_cache=400
    table_open_cache=256

    初始大概只占用 100M,运行一些查询后,也只有几百 M 的样子。

    你的生产环境应该需要适当调整。
    chenxytw
    chenxytw
    Feb 26, 2018❤️1
    8
    内存才占 2.1%...... 你的内存都用来干嘛了 0 0
    和其他服务挤在一起了?
    数据库如果为了比较良好的查询效率 0 0 当然是越高内存越好 0 0
    realpg
    realpg
    Feb 26, 2018❤️3
    9
    加上一句这个,一般立竿见影:

    performance_schema = OFF
    zjiecode
    zjiecode
    Oct 24, 2019❤️1
    10
    @realpg 果然,感谢,配置这个,立竿见影。
    realpg
    realpg
    Oct 25, 2019❤️1
    11
    @mrjiejiejie #10
    多年老中医好使吧。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1027 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 18:43 · PVG 02:43 · LAX 10:43 · JFK 13:43
    ♥ Do have faith in what you're doing.