解决mysql占用资源大的问题

林继 VPS 知识 5,749 共写了1185个字 (2011-11-18 19:49:57) 没有评论 打印 扫描二维码 百度未收录

[level l=0,10]

下载文件
点击这里下载文件
[/level]
在 linux 下,经常出现的情况就是使用 vbB 这种论坛系统时,出现缓慢,mySQL 假死状态,sleep进程过多等等现像。导致几十个用户,就把系统搞定了。
其实这是 mysql 配置上的问题, 默认的 linux 中, mysql 的配置是 my-large.cnf 配置,该配置适合大型服务器。有高内存,比如2G,4G内存的,适合使用,而一般512M内存 的就不行了。它会占用512M内存来保存系统 mysql 的进程,这些进程长期堆质,并不释放,导致系统缓慢。所以,把配置改变成为 /etc/my.cnf ,小型配置就可以了。它的配置如下:

  1. # Example MySQL config file for small systems.
  2. #
  3. # This is for a system with little memory (<= 64M) where MySQL is only used
  4. # from time to time and it's important that the mysqld daemon
  5. # doesn't use much resources.
  6. #
  7. # MySQL programs look for option files in a set of
  8. # locations which depend on the deployment platform.
  9. # You can copy this option file to one of those
  10. # locations. For information about these locations, see:
  11. # http://dev.mysql.com/doc/mysql/en/option-files.html
  12. #
  13. # In this file, you can use all long options that a program supports.
  14. # If you want to know which options a program supports, run the program
  15. # with the "--help" option.
  16.  
  17. # The following options will be passed to all MySQL clients
  18. [client]
  19. #password	= your_password
  20. port		= 3306
  21. socket		= /tmp/mysql.sock
  22.  
  23. # Here follows entries for some specific programs
  24.  
  25. # The MySQL server
  26. [mysqld]
  27. port		= 3306
  28. socket		= /tmp/mysql.sock
  29. skip-locking
  30. skip-innodb
  31. key_buffer_size = 16K
  32. max_allowed_packet = 1M
  33. table_open_cache = 4
  34. sort_buffer_size = 64K
  35. read_buffer_size = 256K
  36. read_rnd_buffer_size = 256K
  37. net_buffer_length = 2K
  38. thread_stack = 128K
  39. max_connections=1000
  40.  
  41. # Don't listen on a TCP/IP port at all. This can be a security enhancement,
  42. # if all processes that need to connect to mysqld run on the same host.
  43. # All interaction with mysqld must be made via Unix sockets or named pipes.
  44. # Note that using this option without enabling named pipes on Windows
  45. # (using the "enable-named-pipe" option) will render mysqld useless!
  46. # 
  47. #skip-networking
  48. server-id	= 1
  49.  
  50. # Uncomment the following if you want to log updates
  51. #log-bin=mysql-bin
  52.  
  53. # binary logging format - mixed recommended
  54. #binlog_format=mixed
  55.  
  56. # Uncomment the following if you are using InnoDB tables
  57. #innodb_data_home_dir = /usr/local/mysql/var
  58. #innodb_data_file_path = ibdata1:10M:autoextend
  59. #innodb_log_group_home_dir = /usr/local/mysql/var
  60. # You can set .._buffer_pool_size up to 50 - 80 %
  61. # of RAM but beware of setting memory usage too high
  62. #innodb_buffer_pool_size = 16M
  63. #innodb_additional_mem_pool_size = 2M
  64. # Set .._log_file_size to 25 % of buffer pool size
  65. #innodb_log_file_size = 5M
  66. #innodb_log_buffer_size = 8M
  67. #innodb_flush_log_at_trx_commit = 1
  68. #innodb_lock_wait_timeout = 50
  69.  
  70. [mysqldump]
  71. quick
  72. max_allowed_packet = 16M
  73.  
  74. [mysql]
  75. no-auto-rehash
  76. # Remove the next comment character if you are not familiar with SQL
  77. #safe-updates
  78.  
  79. [myisamchk]
  80. key_buffer_size = 8M
  81. sort_buffer_size = 8M
  82.  
  83. [mysqlhotcopy]
  84. interactive-timeout

本文来自:http://www.jucoder.com/bbs/thread-6327-0-0.html

分页阅读: 1 2 3 4 下一页

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注

< >