免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4650 | 回复: 11
打印 上一主题 下一主题

[FreeBSD] 求高人优化mysql,服务器负载不高, 但是查询时间长 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-09-04 18:46 |只看该作者 |倒序浏览
last pid: 88433;  load averages:  0.31,  0.44,  0.47                                                                                up 6+20:53:10  18:38:54
131 processes: 2 running, 129 sleeping
CPU:  1.6% user,  0.0% nice,  5.9% system,  0.0% interrupt, 92.4% idle
Mem: 522M Active, 2498M Inact, 563M Wired, 76M Cache, 399M Buf, 263M Free
Swap: 3906M Total, 572K Used, 3906M Free


带宽也没有用多少

                    /0   /1   /2   /3   /4   /5   /6   /7   /8   /9   /10
     Load Average   ||

      Interface           Traffic               Peak                Total
            lo0  in      0.000 KB/s         80.917 KB/s           41.202 GB
                 out     0.000 KB/s         80.917 KB/s           41.202 GB

            re0  in      1.778 KB/s          6.000 KB/s           10.158 GB
                 out    30.377 KB/s         52.244 KB/s           65.441 GB


基本上在100K左右


但是mysql查询时间太长了
装的discuz论坛查询时间



GMT+8, 2009-9-4 18:41, Processed in 0.296042 second(s),



不求太高,只要求新装的discuz论坛查询时间能到 0.0X秒的级别就够了

说一下服务器的配置

Q8200四核cpu    4G内存

WEB环境

操作系统及 PHP FreeBSD / PHP v5.2.9
服务器软件 nginx
MySQL 版本 5.1.34 上传许可 2M



mysql数据库不大, 只有1.5G左右 并且都是小数据库,由100多个小的数据库加起来总共1.5G


按现在的情况, 负载不是很高, 流量也不大, 每天估计ip也就是在1W左右(所有网站的访问量加起来)

但是mysql查询速度却很慢

求高人优化一下mysql的my.cnf文件


现在的my.cnf文件
  1. [client]
  2. #password        = your_password
  3. port                = 3306
  4. socket                = /tmp/mysql.sock

  5. # The MySQL server
  6. [mysqld]
  7. port                = 3306
  8. socket                = /tmp/mysql.sock
  9. skip-locking
  10. key_buffer = 512M
  11. max_allowed_packet = 4M
  12. table_cache = 2048
  13. #sort_buffer_size = 32M
  14. #read_buffer_size = 32M
  15. #read_rnd_buffer_size = 32M
  16. myisam_sort_buffer_size = 128M
  17. thread_cache_size = 128
  18. query_cache_size = 64M
  19. # Try number of CPU's*2 for thread_concurrency
  20. thread_concurrency = 6
  21. wait_timeout = 20
  22. interactive_timeout=10
  23. tmp_table_size=128M
  24. back_log=200
  25. long_query_time    = 2
  26. slow_query_log_file  = /var/log/mysql_slow.log


  27. #skip-networking

  28. server-id        = 1
  29. set-variable    = max_connections=10000
  30. set-variable    = max_connect_errors=99999

  31. [mysqldump]
  32. quick
  33. max_allowed_packet = 16M

  34. [mysql]
  35. no-auto-rehash
  36. # Remove the next comment character if you are not familiar with SQL
  37. #safe-updates

  38. [isamchk]
  39. key_buffer = 256M
  40. sort_buffer_size = 320M
  41. read_buffer = 4M
  42. write_buffer = 4M

  43. [myisamchk]
  44. key_buffer = 256M
  45. sort_buffer_size = 320M
  46. read_buffer = 4M
  47. write_buffer = 4M

  48. [mysqlhotcopy]
  49. interactive-timeout
复制代码

[ 本帖最后由 无名分的浪漫 于 2009-9-5 00:05 编辑 ]

论坛徽章:
2
丑牛
日期:2013-09-29 09:47:222015七夕节徽章
日期:2015-08-21 11:06:17
2 [报告]
发表于 2009-09-04 19:05 |只看该作者
http://www.bsdlover.cn/html/69/n-1069.html
根据内存选个推荐的my.cnf吧

论坛徽章:
0
3 [报告]
发表于 2009-09-05 00:01 |只看该作者
谢谢 剑心通明 大哥了
我慢慢研究一下!!

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
4 [报告]
发表于 2009-09-05 09:47 |只看该作者
如果要简单一点的话,你实际上可以利用phpMyAdmin,查看服务器运行的情况,做针对性的调整。

论坛徽章:
0
5 [报告]
发表于 2009-09-05 17:56 |只看该作者
我觉得你对配置文件不存在什么问题。
让mysql把slow query记录下来。然后explain看看。

论坛徽章:
0
6 [报告]
发表于 2009-09-06 02:39 |只看该作者
有报酬不,如果有报酬应会有很多人,这年头雷峰不容易找

论坛徽章:
0
7 [报告]
发表于 2009-09-07 11:26 |只看该作者
安装了类似eAccelerator的程序了吗?
eAccelerator可以在一定程度上提高php的性能(经过实际测试,以bbs.codeday.com为例,在100人在线的时候,首页打开时间大概提高了0.02秒(未安装之前是0.06左右,安装之后为0.04),也就是大概提升了三分之一的速度。
见:http://bbs.laxjyj.com/read-htm-tid-29886.html

论坛徽章:
0
8 [报告]
发表于 2009-09-07 14:50 |只看该作者
这个不算高,优化一下DZ吧,去掉不要的功能。

论坛徽章:
0
9 [报告]
发表于 2009-09-07 14:54 |只看该作者

这是我的

  1. web# cat my.cnf
  2. [client]
  3. #password       = your_password
  4. port            = 3306
  5. socket          = /tmp/mysql.sock

  6. [mysqld]
  7. port            = 3306
  8. socket          = /tmp/mysql.sock
  9. skip-innodb
  10. #skip-bdb
  11. bind-address=127.0.0.1
  12. skip-name-resolve
  13. skip-locking
  14. back_log = 1024
  15. #log-bin
  16. set-variable = key_buffer=4096M
  17. set-variable = max_allowed_packet=4M
  18. set-variable = table_cache=1024
  19. set-variable = thread_cache=512
  20. set-variable = join_buffer_size=32M
  21. set-variable = sort_buffer=64M
  22. set-variable = record_buffer=256M
  23. set-variable = max_connections=1024
  24. set-variable = wait_timeout=20
  25. set-variable = interactive_timeout=120
  26. set-variable = max_connect_errors=40000
  27. set-variable = long_query_time=1
  28. set-variable = max_heap_table_size=256M
  29. set-variable = tmp_table_size=128M
  30. set-variable = thread_concurrency=16
  31. set-variable = myisam_sort_buffer_size=256M

  32. key_buffer_size = 4096M
  33. max_allowed_packet = 4M
  34. wait_timeout = 20
  35. table_open_cache = 2048
  36. sort_buffer_size = 8M
  37. read_buffer_size = 8M
  38. read_rnd_buffer_size = 16M
  39. myisam_sort_buffer_size = 256M
  40. thread_cache_size = 64
  41. query_cache_size = 256M
  42. # Try number of CPU's*2 for thread_concurrency
  43. thread_concurrency = 16


  44. # Don't listen on a TCP/IP port at all. This can be a security enhancement,
  45. # if all processes that need to connect to mysqld run on the same host.
  46. # All interaction with mysqld must be made via Unix sockets or named pipes.
  47. # Note that using this option without enabling named pipes on Windows
  48. # (via the "enable-named-pipe" option) will render mysqld useless!
  49. #
  50. #skip-networking

  51. # Replication Master Server (default)
  52. # binary logging is required for replication
  53. #log-bin=mysql-bin

  54. # required unique id between 1 and 2^32 - 1
  55. # defaults to 1 if master-host is not set
  56. # but will not function as a master if omitted
  57. server-id       = 1

  58. # Replication Slave (comment out master section to use this)
  59. #
  60. # To configure this host as a replication slave, you can choose between
  61. # two methods :
  62. #
  63. # 1) Use the CHANGE MASTER TO command (fully described in our manual) -
  64. #    the syntax is:
  65. #
  66. #    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
  67. #    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
  68. #
  69. #    where you replace <host>, <user>, <password> by quoted strings and
  70. #    <port> by the master's port number (3306 by default).
  71. #
  72. #    Example:
  73. #
  74. #    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
  75. #    MASTER_USER='joe', MASTER_PASSWORD='secret';
  76. #
  77. # OR
  78. #
  79. # 2) Set the variables below. However, in case you choose this method, then
  80. #    start replication for the first time (even unsuccessfully, for example
  81. #    if you mistyped the password in master-password and the slave fails to
  82. #    connect), the slave will create a master.info file, and any later
  83. #    change in this file to the variables' values below will be ignored and
  84. #    overridden by the content of the master.info file, unless you shutdown
  85. #    the slave server, delete master.info and restart the slaver server.
  86. #    For that reason, you may want to leave the lines below untouched
  87. #    (commented) and instead use CHANGE MASTER TO (see above)
  88. #
  89. # required unique id between 2 and 2^32 - 1
  90. # (and different from the master)
  91. # defaults to 2 if master-host is set
  92. # but will not function as a slave if omitted
  93. #server-id       = 2
  94. #
  95. # The replication master for this slave - required
  96. #master-host     =   <hostname>
  97. #
  98. # The username the slave will use for authentication when connecting
  99. # to the master - required
  100. #master-user     =   <username>
  101. #
  102. # The password the slave will authenticate with when connecting to
  103. # the master - required
  104. #master-password =   <password>
  105. #
  106. # The port the master is listening on.
  107. # optional - defaults to 3306
  108. #master-port     =  <port>
  109. #
  110. # binary logging - not required for slaves, but recommended
  111. #log-bin=mysql-bin
  112. #
  113. # binary logging format - mixed recommended
  114. #binlog_format=mixed

  115. # Point the following paths to different dedicated disks
  116. #tmpdir         = /tmp/
  117. #log-update     = /path-to-dedicated-directory/hostname

  118. # Uncomment the following if you are using InnoDB tables
  119. #innodb_data_home_dir = /var/db/mysql/
  120. #innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
  121. #innodb_log_group_home_dir = /var/db/mysql/
  122. # You can set .._buffer_pool_size up to 50 - 80 %
  123. # of RAM but beware of setting memory usage too high
  124. #innodb_buffer_pool_size = 384M
  125. #innodb_additional_mem_pool_size = 20M
  126. # Set .._log_file_size to 25 % of buffer pool size
  127. #innodb_log_file_size = 100M
  128. #innodb_log_buffer_size = 8M
  129. #innodb_flush_log_at_trx_commit = 1
  130. #innodb_lock_wait_timeout = 50

  131. [mysqldump]
  132. quick
  133. max_allowed_packet = 16M

  134. [mysql]
  135. no-auto-rehash
  136. # Remove the next comment character if you are not familiar with SQL
  137. #safe-updates

  138. [myisamchk]
  139. key_buffer_size = 512M
  140. sort_buffer_size = 512M
  141. read_buffer = 8M
  142. write_buffer = 4M

  143. [mysqlhotcopy]
  144. interactive-timeout
复制代码

论坛徽章:
0
10 [报告]
发表于 2009-09-07 14:55 |只看该作者
  1. last pid: 98260;  load averages:  0.55,  0.60,  0.54                                                                 up 57+09:01:48  14:53:28
  2. 353 processes: 2 running, 351 sleeping
  3. CPU:  4.7% user,  0.0% nice,  2.2% system,  0.0% interrupt, 93.1% idle
  4. Mem: 1837M Active, 16G Inact, 410M Wired, 85M Cache, 63M Buf, 12G Free
  5. Swap: 32G Total, 32G Free

  6.   PID USERNAME    THR PRI NICE   SIZE    RES STATE  C   TIME   WCPU COMMAND
  7. 56708 mysql        66  44    0  4597M  1366M ucond  1   0:22  3.03% mysqld
  8. 98221 www           1   4    0 11160K  5084K kqread 2   0:07  0.49% nginx
  9. 98149 www           1   4    0 49196K 12908K accept 1   0:01  0.29% php-cgi
  10. 98115 www           1   4    0 49196K 13112K accept 1   0:01  0.20% php-cgi
  11. 98081 www           1   4    0 49196K 13140K accept 0   0:02  0.10% php-cgi
  12. 98109 www           1   4    0 49196K 12724K accept 1   0:02  0.10% php-cgi
  13. 98096 www           1   4    0 49196K 13184K accept 1   0:02  0.10% php-cgi
  14. 98093 www           1   4    0 49196K 13188K accept 1   0:02  0.10% php-cgi
  15. 98094 www           1   4    0 49196K 12852K accept 2   0:02  0.10% php-cgi
  16. 98111 www           1   4    0 49196K 12952K accept 2   0:02  0.10% php-cgi
  17. 98097 www           1   4    0 49196K 13140K accept 0   0:02  0.10% php-cgi
  18. 98082 www           1   4    0 49196K 12852K accept 3   0:02  0.10% php-cgi
  19. 98078 www           1   4    0 49196K 13196K accept 0   0:02  0.10% php-cgi
  20. 98092 www           1   4    0 49196K 12944K accept 0   0:02  0.10% php-cgi
  21. 98102 www           1   4    0 49196K 12760K accept 3   0:02  0.10% php-cgi
  22. 98106 www           1   4    0 49196K 12824K accept 0   0:02  0.10% php-cgi
  23. 98107 www           1   4    0 49196K 13132K accept 2   0:02  0.10% php-cgi
  24. 98067 www           1   4    0 49196K 13148K accept 1   0:02  0.10% php-cgi
  25. 98066 www           1   4    0 49196K 12944K accept 0   0:02  0.10% php-cgi
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP