【发布时间】:2014-02-22 19:30:18
【问题描述】:
我的服务器遇到了一个奇怪的问题。我安装了 MariaDB,它可以工作。我可以设置数据库和一切。但是每次 MariaDB 需要写入数据(例如插入新行、创建数据库、删除行...)时,都需要很长时间。
目前,我无法设置基本的 WordPress 网站,因为创建数据库的时间太长,以至于我的浏览器超时。
即使是 drop database X 语句也需要 30 多秒,对于几乎空的数据库。
我真的不明白为什么,因为我已经在其他机器上成功安装了 MySQL,这些机器的性能远低于这台机器(32 GB RAM、SSDdrive、Intel(R) Xeon(R) CPU E3-1245 V2 @ 3.40GHz,8 核 CPU 等)。
我不知道如何调试。这是我所做的:
运行 MySQLTuner(在 this question 中找到)
输出:
-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[!!] Your MySQL version 10.0.7-MariaDB-1~wheezy-log is EOL software! Upgrade soon!
[OK] Operating on 64-bit architecture
-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB +Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 6K (Tables: 39)
[--] Data in CSV tables: 0B (Tables: 2)
[--] Data in InnoDB tables: 237K (Tables: 214)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 52)
[!!] Total fragmented tables: 146
-------- Security Recommendations -------------------------------------------
[OK] All database users have passwords assigned
Use of uninitialized value in addition (+) at ./mysqltuner.pl line 582, <> line
2 (#1)
(W uninitialized) An undefined value was used as if it were already
defined. It was interpreted as a "" or a 0, but maybe it was a mistake.
To suppress this warning assign a defined value to your variables.
To help you figure out what was undefined, perl will try to tell you the
name of the variable (if any) that was undefined. In some cases it cannot
do this, so it also tells you what operation you used the undefined value
in. Note, however, that perl optimizes your program and the operation
displayed in the warning may not necessarily appear literally in your
program. For example, "that $foo" is usually optimized into "that "
. $foo, and the warning will refer to the concatenation (.) operator,
even though there is no . in your program.
Argument "xargs:" isn't numeric in addition (+) at ./mysqltuner.pl line 618, <>
line 2 (#2)
(W numeric) The indicated string was fed as an argument to an operator
that expected a numeric value instead. If you're fortunate the message
will identify which operator was so unfortunate.
Argument "du:" isn't numeric in addition (+) at ./mysqltuner.pl line 618, <>
line 2 (#2)
-------- Performance Metrics -------------------------------------------------
[--] Up for: 21m 17s (818 q [0.641 qps], 36 conn, TX: 395K, RX: 338K)
[--] Reads / Writes: 73% / 27%
[--] Total buffers: 1.3G global + 416.0K per thread (100 max threads)
[OK] Maximum possible memory usage: 1.4G (4% of installed RAM)
[OK] Slow queries: 0% (3/818)
[OK] Highest usage of available connections: 3% (3/100)
[!!] Cannot calculate MyISAM index size - re-run script as root user
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 11 sorts)
[!!] Temporary tables created on disk: 47% (90 on disk / 189 total)
[OK] Thread cache hit rate: 91% (3 created / 36 connections)
[OK] Table cache hit rate: 211% (91 open / 43 opened)
[OK] Open file limit used: 3% (34/1K)
[OK] Table locks acquired immediately: 100% (603 immediate / 603 locks)
[!!] Connections aborted: 16%
[OK] InnoDB data size / buffer pool: 237.4K/256.0M
-------- Recommendations -----------------------------------------------------
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
MySQL started within last 24 hours - recommendations may be inaccurate
Upgrade MySQL to version 4+ to utilize query caching
Temporary table size is already large - reduce result set size
Reduce your SELECT DISTINCT queries without LIMIT clauses
Upgrade to MySQL 4.1+ to use concurrent MyISAM inserts
Your applications are not closing MySQL connections properly
似乎有很多错误的事情(!!)。但为什么 ?据我所知,我通过他们的网站安装了标准的 Mariadb。
Drop database XXX 的分析
MariaDB [(none)]> set profiling = 1;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> drop database XXX;
Query OK, 11 rows affected (20.08 sec)
MariaDB [(none)]> show profile for query 1;
+------------------------------+-----------+
| Status | Duration |
+------------------------------+-----------+
| Table lock | 0.000008 |
| Waiting for query cache lock | 0.000004 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000008 |
| Table lock | 0.000008 |
| Opening tables | 0.000010 |
| System lock | 0.000004 |
| Table lock | 0.000008 |
| Waiting for query cache lock | 0.000005 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000007 |
| Opening tables | 0.000010 |
| System lock | 0.000004 |
| Table lock | 0.000008 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000007 |
| Opening tables | 0.000010 |
| System lock | 0.000004 |
| Table lock | 0.000013 |
| Waiting for query cache lock | 0.000005 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000007 |
| Opening tables | 0.000010 |
| System lock | 0.000004 |
| Table lock | 0.000008 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000008 |
| Opening tables | 0.000010 |
| System lock | 0.000004 |
| Table lock | 0.000008 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000007 |
| Opening tables | 0.000010 |
| System lock | 0.000004 |
| Table lock | 0.000008 |
| Waiting for query cache lock | 0.000004 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 12.399188 | # WHAAAT ?
| Waiting for query cache lock | 0.000012 |
| Table lock | 0.000005 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000004 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.000003 |
| Waiting for query cache lock | 0.000003 |
| Table lock | 0.299851 |
| Waiting for query cache lock | 0.000007 |
| Table lock | 0.000008 |
| Opening tables | 0.000017 |
| System lock | 0.000008 |
| Table lock | 0.000019 |
| Waiting for query cache lock | 0.000004 |
| Table lock | 0.000013 |
| Opening tables | 0.000012 |
| System lock | 0.000004 |
| Table lock | 0.000015 |
| Waiting for query cache lock | 0.000004 |
| Table lock | 0.000093 |
| query end | 0.000007 |
| closing tables | 0.000014 |
| freeing items | 0.000005 |
| updating status | 0.000013 |
| cleaning up | 0.000015 |
+------------------------------+-----------+
所以说table lock有问题,但不知道跟哪些设置有关。
“锁定”相关变量
show variables LIKE '%lock%';
+-----------------------------------------+------------+
| Variable_name | Value |
+-----------------------------------------+------------+
| aria_block_size | 8192 |
| deadlock_search_depth_long | 15 |
| deadlock_search_depth_short | 4 |
| deadlock_timeout_long | 50000000 |
| deadlock_timeout_short | 10000 |
| innodb_api_disable_rowlock | OFF |
| innodb_autoinc_lock_mode | 1 |
| innodb_lock_wait_timeout | 50 |
| innodb_locks_unsafe_for_binlog | OFF |
| innodb_old_blocks_pct | 37 |
| innodb_old_blocks_time | 1000 |
| innodb_print_all_deadlocks | OFF |
| innodb_table_locks | ON |
| key_cache_block_size | 1024 |
| lock_wait_timeout | 31536000 |
| locked_in_memory | OFF |
| max_write_lock_count | 4294967295 |
| metadata_locks_cache_size | 1024 |
| metadata_locks_hash_instances | 8 |
| myisam_block_size | 1024 |
| performance_schema_max_rwlock_classes | 40 |
| performance_schema_max_rwlock_instances | 1667 |
| query_alloc_block_size | 8192 |
| query_cache_wlock_invalidate | OFF |
| range_alloc_block_size | 4096 |
| skip_external_locking | ON |
| transaction_alloc_block_size | 8192 |
+-----------------------------------------+------------+
Variables (sudo mysqld --help --verbose)
如果您需要更多信息,请告诉我。感谢您的帮助!
【问题讨论】:
-
在野外拍摄:也许 mysql 服务器配置为刷新/写入每个更改到磁盘?
-
也许其他一些查询运行缓慢并延迟了表锁定?
-
@arkascha 也许,但我该如何检查呢? ToBe 你有什么我可以检查的吗?
-
试试 SHOW PROCESS LIST mariadb.com/kb/en/show-processlist 和 mariadb.com/kb/en/show-engine-innodb-status