免费注册 查看新帖 |

Chinaunix

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

Mysql 数据库如何优化? [复制链接]

论坛徽章:
1
丑牛
日期:2014-05-22 15:38:58
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-02-24 15:42 |只看该作者 |倒序浏览
本帖最后由 smallfish 于 2011-02-24 15:45 编辑

网站用的是discuz 的程序,大部分用的是博客。最近发现网站运行速度超级慢,登录服务器发现负载很高,每次都要重启mysql服务,能维持2天左右,过2天又慢了,数据库大概3G。把图片贴上来给大家看看,帮忙参谋一下如何解决。

UC_HOME 数据库几个大容量的表:
2.1G      uchome_blogfield.MYD
3.8M      uchome_blogfield.MYI
16K       uchome_blog.frm
190M      uchome_blog.MYD
20M       uchome_blog.MYI
16K        uchome_post.frm
955M      uchome_post.MYD
1.9M       uchome_post.MYI

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:48:00
2 [报告]
发表于 2011-02-24 17:35 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
1
丑牛
日期:2014-05-22 15:38:58
3 [报告]
发表于 2011-02-24 21:34 |只看该作者
谢谢,我测试一下,如果大家有更好的办法,麻烦指点一下,非常感谢!

论坛徽章:
1
丑牛
日期:2014-05-22 15:38:58
4 [报告]
发表于 2011-02-25 11:04 |只看该作者
附上一点服务器运行记录:
此 MySQL 服务器已经运行了 1 天 13 小时,14 分 30 秒,启动时间为 2011 年 02 月 23 日 21:44。

查询统计:自从启动后,服务器共收到了 1,762,940 次查询。

查询量最大的几个:

查询方式                         ø 每小时          %               
change db                               4,656.05              11.06%            
select                                     20.51 k                 48.70%
set option                                11.09 k                 26.33%
update                                2,961.52                  7.03%

论坛徽章:
0
5 [报告]
发表于 2011-02-25 12:57 |只看该作者
感觉是mysql的配置有问题。你把你的配置贴一下,也贴以下io的情况。

论坛徽章:
0
6 [报告]
发表于 2011-02-25 17:19 |只看该作者
上图显示mysql占用CPU是13.5,并不高,而服务器的平均负载有些高,不一定是mysql的问题吧,除了mysql之外还运行的有其它的服务?

论坛徽章:
1
丑牛
日期:2014-05-22 15:38:58
7 [报告]
发表于 2011-02-27 00:42 |只看该作者
谢谢!其他服务就是APACHE,TOMCAT.感觉MYSQL有问题,每次网站打不开我重启MYSQL就好了。应该需要优化,但是我在my.cnf里没看到slow query的相关设置.

大概的配置整理如下:

# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# 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 /usr/local/mysql/data) or
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-locking
key_buffer = 16M
max_allowed_packet = 1M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
max_connections = 1000
#skip-networking
set-variable=local-infile=0
#--end--
# Replication Master Server (default)
# binary logging is required for replication
#log-bin=mysql-bin

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
[mysqldump]
quick
max_allowed_packet = 16M

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

[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

server-id       = 1

论坛徽章:
0
8 [报告]
发表于 2011-02-28 11:22 |只看该作者
配置文件加上log-slow-queries吧,重启mysqld。

另外在慢的时候跑下iostat -x 2,看看io的情况。

论坛徽章:
1
丑牛
日期:2014-05-22 15:38:58
9 [报告]
发表于 2011-02-28 12:38 |只看该作者
好的,我测试一下,谢谢!
有的人说要优化日志表,不知道咋弄

论坛徽章:
0
10 [报告]
发表于 2011-02-28 14:33 |只看该作者
回复 9# smallfish

具体情况要具体分析,不是很了解你的数据情况,不发表意见,呵呵。

不过一般情况下,日志表的优化就是分表了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP