【问题标题】:Very slow mysql很慢的mysql
【发布时间】:2009-11-23 22:58:48
【问题描述】:

我的服务器 mysql 有一个大问题。一切都很好,但自从一周以来,它非常缓慢。 每个查询都很慢(有时超过 20 秒)。 我的配置没有任何改变。

谁能帮我知道为什么我的服务器现在变慢了?

谢谢。

这是我的 my.cnf:

[

mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
#
# * Basic Settings
#
user        = mysql
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
language    = /usr/share/mysql/english
#join_buffer_size   = 128.0K
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = 127.0.0.1
# * Fine Tuning
#
key_buffer      = 16M
max_allowed_packet  = 16M
max_heap_table_size = 64M
tmp_table_size      = 64M

thread_stack        = 128K
thread_cache_size   = 8
#max_connections        = 100
table_cache            = 400 
join_buffer_size    = 2000K
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit       = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
#log        = /var/log/mysql/mysql.log
#
# Error logging goes to syslog. This is a Debian improvement :)
#
# Here you can see queries with especially long duration
log_slow_queries    = /var/log/mysql/mysql-slow.log
long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
#server-id      = 1
log_bin         = /var/log/mysql/mysql-bin.log
# WARNING: Using expire_logs_days without bin_log crashes the server! See README.Debian!
expire_logs_days    = 10
max_binlog_size         = 100M
#binlog_do_db       = include_database_name
#binlog_ignore_db   = include_database_name
#
# * BerkeleyDB
#
# Using BerkeleyDB is now discouraged as its support will cease in 5.1.12.
skip-bdb
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
# You might want to disable InnoDB to shrink the mysqld process by circa 100MB.
#skip-innodb
innodb_buffer_pool_size = 42M
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem



[mysqldump]
quick
quote-names
max_allowed_packet  = 16M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completition

[isamchk]
key_buffer      = 16M

【问题讨论】:

  • 您使用的确切查询和表架构是什么?表中有多少行?
  • 发布查询,并在您的查询上发布 EXPLAIN 的输出。可能 - 当您将更多数据倒入表中时,mysql 切换到使用错误的索引,并且/或者您没有正确的索引。
  • 看起来_run_faster = 1 变量没有在 my.cnf 中设置。 (我开玩笑,我开玩笑。)

标签: mysql


【解决方案1】:

假设在资源方面(CPU、内存、磁盘活动)没有任何变化——要研究的一个领域可能是查询的索引。假设不断输入/更新数据,那么随着输入越来越多的数据,查询可能会随着时间的推移而减慢——尤其是在没有设置索引的情况下。如果没有关于您的整个设置的更多信息,这类问题很难回答。

【讨论】:

    【解决方案2】:

    不是一个真正的答案,但 mysql 的正常运行时间是多长时间?也许重新启动它会有所帮助?

    如果重新启动没有帮助 - 对所有活动数据库/表运行检查,其中一些可能已损坏并导致问题。

    另外,你的mysql服务器系统的负载是多少?某些东西可能会吃掉所有的 RAM 并导致大量交换。您可以使用htopfree 以及其他一些工具来监控CPU/RAM 的使用情况。

    【讨论】:

    • 我怀疑正常运行时间与它有什么关系。这不是 Windows 95 ;)
    • 没有完美的软件,我知道(从那时起已修复)uptime 实用程序故障在较长的正常运行时间(256d-3y 范围内的某个地方)后:它从 0 天正常运行时间重新开始计数.无论如何,Kiva 的更新清楚地表明我在这种情况下是错的 :)
    【解决方案3】:

    这个数据库用于什么类型的应用程序?

    这可能是一个长镜头,但我曾经通过一个应用程序监视服务器,该应用程序为支持应用程序导入电子邮件。过了一会儿,我注意到应用程序开始变慢。事实证明,由于垃圾邮件使其中一张表溢出,数据库变得非常庞大。把它们清理干净,它明显振作起来。

    确保没有出现问题并让数据库中充斥着垃圾数据。不是可能的原因,但检查一下不会有什么坏处。

    在任何情况下,请确保您没有过度使用交换(如其他地方所建议的那样)。

    【讨论】:

    • 我的数据库被 postfix 用于发送邮件,并被 rails (mongrel) 用于我的网站。只有两个应用程序。我每天发送大约 10 封邮件。
    【解决方案4】:

    您可以尝试通过使用some tools 监控性能来缩小问题范围, 对于 unix 系统,还有一个名为 mytop 的工具,通常可以通过包管理系统获得...

    另外,尝试在表上创建一些索引以减少访问延迟。

    【讨论】:

      【解决方案5】:

      感谢您的回答。

      我尝试重新启动我的 mysql 服务器,但没有任何改变。关于 cpu 和 ram,没有错,我的 cpu 大约是 2%,我有 100Mo 免费安装 1 个 Go。

      我在所有表上运行了 OPTIMIZE TABLE,但问题仍然存在。

      但是,我分析I/O硬盘,我的硬盘每次都写很多东西。我的磁盘上平均有 75.33 个请求/秒写入。

      问题可能就在这里。怎么知道每次写什么程序?

      【讨论】:

        【解决方案6】:

        尝试在skip-external-locking之后添加选项skip-name-resolve,如果在/etc/hosts中添加服务器IP地址和域也是一样的。

        我有同样的情况,添加这个解决了问题!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-08-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多