溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

mysql占用資源過大如何解決

發(fā)布時間:2021-08-04 17:09:32 來源:億速云 閱讀:221 作者:Leah 欄目:數(shù)據(jù)庫

mysql占用資源過大如何解決,針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

    在 linux 下,經(jīng)常出現(xiàn)的情況就是使用 VBB 這種系統(tǒng)時,出現(xiàn)緩慢, 假死狀態(tài),sleep進(jìn)程過多等等現(xiàn)像。導(dǎo)致幾十個用戶,就把系統(tǒng)搞定了。
    其實這是 mysql 配置上的問題, 默認(rèn)的 linux 中, mysql 的配置是 my-large.cnf 配置,該配置適合大型服務(wù)器。有高內(nèi)存,比如2G,4G內(nèi)存的,適合使用,而一般512M內(nèi)存 的就不行了。它會占用512M內(nèi)存來保存系統(tǒng) mysql 的進(jìn)程,這些進(jìn)程長期堆質(zhì),并不釋放,導(dǎo)致系統(tǒng)緩慢。所以,把配置改變成為 my-small.cnf ,小型配置就可以了。它的配置如下:
    # Example mysql config file for small systems.
    #
    # This is for a system with little memory (<= 64M) where MySQL is only used
    # from time to time and its important that the mysqld deamon
    # doesnt use much resources.
    #
    # You can copy this file to
    # /etc/my.cnf to set global options,
    # mysql-data-dir/my.cnf to set server-specific options (in this
    # installation this directory is /var/lib/mysql) or
    # ~/.my.cnf to set user-specific options.
    #
    # One can in this file use all long options that the program supports.
    # If you want to know which options a program support, run the program
    # with --help option.
    # The following options will be passed to all MySQL clients
    [client]
    #password = 你的密碼
    port = 3306
    socket = /tmp/mysql.sock
    # Here follows entries for some specific programs
    # The MySQL server
    [mysqld]
    port = 3306
    socket = /tmp/mysql.sock
    skip-locking
    set-variable = key_buffer=16K
    set-variable = max_allowed_packet=1M
    set-variable = thread_stack=64K
    set-variable = table_cache=4
    set-variable = sort_buffer=64K
    set-variable = net_buffer_length=2K
    server-id = 1
    # Uncomment the following if you want to log updates
    #log-bin
    # Uncomment the following if you are NOT using BDB tables
    #skip-bdb
    # Uncomment the following if you are using InnoDB tables
    #innodb_data_home_dir = /var/lib/mysql/
    #innodb_data_file_path = ibdata1:10M:autoextend
    #innodb_log_group_home_dir = /var/lib/mysql/
    #innodb_log_arch_dir = /var/lib/mysql/
    # You can set .._buffer_pool_size up to 50 - 80 %
    # of RAM but beware of setting memory usage too high
    #set-variable = innodb_buffer_pool_size=16M
    #set-variable = innodb_additional_mem_pool_size=2M
    # Set .._log_file_size to 25 % of buffer pool size
    #set-variable = innodb_log_file_size=5M
    #set-variable = innodb_log_buffer_size=8M
    #innodb_flush_log_at_trx_commit=1
    #set-variable = innodb_lock_wait_timeout=50
    [mysqldump]
    quick
    set-variable = max_allowed_packet=16M
    [mysql]
    no-auto-rehash
    # Remove the next comment character if you are not familiar with SQL
    #safe-updates
    [isamchk]
    set-variable = key_buffer=8M
    set-variable = sort_buffer=8M
    [myisamchk]
    set-variable = key_buffer=8M
    set-variable = sort_buffer=8M
    [mysqlhotcopy]
    interactive-timeout

關(guān)于mysql占用資源過大如何解決問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI