Mysql更新时间长而且卡住

标签 mysql debian percona

在随机时间(不取决于网站的流量)mysql 更新被卡住。我们使用 MySQL 5.5.46-0+deb8u1 - (Debian) 然后将其更改为:Percona Server 版本:5.5.47-37.7-log - Percona Server (GPL),版本 37.7,修订版 764f304 问题相同。

mytop

横幅统计表的结构

CREATE TABLE `banner_stat` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `date` date NOT NULL,
  `banner_id` int(11) NOT NULL,
  `appear` int(11) NOT NULL,
  `click` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `banner_id` (`banner_id`),
  KEY `date` (`date`)
) ENGINE=InnoDB AUTO_INCREMENT=6289 DEFAULT CHARSET=latin1

我们的mysql配置:

[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0
[mysqld]
#
# * Basic Settings
#
expire_logs_days=2
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
lc-messages-dir = /usr/share/mysql
skip-external-locking
skip-host-cache
skip-name-resolve
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = *.*.*.*
#
# * Fine Tuning
#
tmp_table_size      = 256M
max_heap_table_size = 256M
sort_buffer_size = 8M
read_buffer_size = 8M
join_buffer_size = 12M
key_buffer_size     = 400M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover         = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit   = 128K
#query_cache_min_res_unit = 2k
query_cache_type = 1
query_cache_size        = 45M
#query_cache_limit  = 0
#query_cache_size   = 0
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
slow_query_log_file = /var/log/mysql/mysql-slow.log
slow_query_log      = 1
#long_query_time = 1
#log_queries_not_using_indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
server-id       = 1
log_bin         = /var/log/mysql/mysql-bin.log
max_binlog_size         = 100M
binlog_do_db        = binlog
#binlog_ignore_db   = include_database_name
#
# * 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!
innodb_buffer_pool_size = 160M
#
# * 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
#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

我们使用带有 Debian 操作系统的 4 核和 8GB RAM 服务器。

如果您知道导致此问题的原因,或者您知道我们如何解决它,请写信。

最佳答案

你的innodb配置部分有点空。我认为默认设置对于您的数据库来说不够。试试这个:

innodb_buffer_pool_size = 5000M
innodb_buffer_pool_instances = 8
innodb_log_file_size = 100M
innodb_log_buffer_size = 10M
innodb_flush_log_at_trx_commit = 2

关于Mysql更新时间长而且卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35452429/

相关文章:

linux - 为什么 32 位 .deb 包不能安装在 64 位 Ubuntu 上?

linux - 如何安全地将 apache 版本降级到不适合当前 gnome 状态的版本?

MySQL 服务不再启动

php - 使用 pt-online-schema-change 是否可以在代码库部署的 "swap"阶段暂停?

c# - 使用 SQL 在 C# 中使用 Combobox

MySQL 查询 - 今天和过去 30 天之间的记录

mysql - 将 UTF-8 编码的转储加载到 MySQL

php - 实现我的第一个 PHP 模型

mysql - Percona Xtradb-长时间停机后无法启动节点

mysql - 低执行时间(100 毫秒)高获取时间(4 秒)但其他查询没问题