V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
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
V2EX  ›  MySQL

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

  •  
  •   R18 · 2018-02-26 09:13:12 +08:00 · 8349 次点击
    这是一个创建于 2222 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 条回复    2019-10-25 00:09:37 +08:00
    msg7086
        1
    msg7086  
       2018-02-26 09:22:42 +08:00   ❤️ 1
    内存占用 2.1%,我觉得还好啊?
    R18
        2
    R18  
    OP
       2018-02-26 09:25:36 +08:00
    @msg7086 他有很多个 2.1% 啊
    chenqh
        3
    chenqh  
       2018-02-26 09:26:26 +08:00 via iPhone   ❤️ 1
    htop 的 bug 你用 top 看
    msg7086
        4
    msg7086  
       2018-02-26 09:28:24 +08:00   ❤️ 1
    很多个 2.1%也是 2.1%啊,又不会加起来……
    你先切成树状图看看,MySQL 那么多都是线程啊,内存是线程间共享的好么。
    kungfuchicken
        5
    kungfuchicken  
       2018-02-26 09:28:26 +08:00   ❤️ 1
    suconghou
        6
    suconghou  
       2018-02-26 09:29:05 +08:00   ❤️ 1
    @chenqh @R18 并不是 Bug 这里显示的是线程,mysql 是多线程的。在 htop 里使用 H 可以切换是否以线程方式显示。
    my101du
        7
    my101du  
       2018-02-26 09:40:28 +08:00   ❤️ 1
    根据这篇 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
        8
    chenxytw  
       2018-02-26 10:22:47 +08:00   ❤️ 1
    内存才占 2.1%...... 你的内存都用来干嘛了 0 0
    和其他服务挤在一起了?
    数据库如果为了比较良好的查询效率 0 0 当然是越高内存越好 0 0
    realpg
        9
    realpg  
       2018-02-26 12:54:29 +08:00   ❤️ 2
    加上一句这个,一般立竿见影:

    performance_schema = OFF
    zjiecode
        10
    zjiecode  
       2019-10-24 22:56:56 +08:00   ❤️ 1
    @realpg 果然,感谢,配置这个,立竿见影。
    realpg
        11
    realpg  
       2019-10-25 00:09:37 +08:00
    @mrjiejiejie #10
    多年老中医好使吧。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3914 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 10:28 · PVG 18:28 · LAX 03:28 · JFK 06:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.