MySQL/MariaDB写入/插入需要很长时间

MySQL/MariaDB写入/插入需要很长时间,mysql,wordpress,mariadb,Mysql,Wordpress,Mariadb,我在服务器上遇到了一个奇怪的问题。我已经安装了MariaDB,它可以正常工作。我可以建立数据库和一切。但每次MariaDB需要写入数据(例如,插入新行、创建数据库、删除行……)都需要很长时间 现在,我无法设置基本的WordPress网站,因为创建数据库的时间太长,以致我的浏览器超时 即使是drop database X语句,对于一个几乎为空的数据库也需要30秒以上的时间 我真的不明白为什么,因为我已经成功地在其他机器上安装了MySQL,而这些机器的性能远远低于这台机器(32 GB RAM、SSD

我在服务器上遇到了一个奇怪的问题。我已经安装了MariaDB,它可以正常工作。我可以建立数据库和一切。但每次MariaDB需要写入数据(例如,插入新行、创建数据库、删除行……)都需要很长时间

现在,我无法设置基本的WordPress网站,因为创建数据库的时间太长,以致我的浏览器超时

即使是
drop database X
语句,对于一个几乎为空的数据库也需要30秒以上的时间

我真的不明白为什么,因为我已经成功地在其他机器上安装了MySQL,而这些机器的性能远远低于这台机器(32 GB RAM、SSD、Intel(R)Xeon(R)CPU E3-1245 V2@3.40GHz、8核CPU等)

我不知道如何调试这个。以下是我所做的:

运行MySQLTuner(在中找到) 产出:

-------- 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
所以表锁有问题,但我不知道它与哪些设置有关

“锁定”相关变量 变量(sudomysqld--help--verbose) [mysqld--help--verbose)


如果您需要更多信息,请告诉我。谢谢您的帮助!

好的,我不知道到底是什么问题,但在浏览了网上的几十个主题后,我用以下值更新了我的
my.cnf
文件:

query_cache_type = OFF
slow_query_log = 1 # log slow queries, for debuging
long_query_time = 1 # log queries as slow when their duration > 1 sec
innodb_buffer_pool_size = 1500M
innodb_log_buffer_size  = 80M
innodb_flush_log_at_trx_commit = 0 # I know it's not good for transaction security but it seemed to help
就这些

我现在可以从浏览器中创建数据库,即使它仍然有点慢(在我看来),现在也好多了


感谢我们的帮助!

野外拍摄:可能mysql服务器配置为刷新/写入磁盘上的每一个更改?可能其他查询运行缓慢并延迟了表锁?@arkascha可能,但我如何检查?你有什么方法可以检查吗?试着显示进程列表并
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       |
+-----------------------------------------+------------+
query_cache_type = OFF
slow_query_log = 1 # log slow queries, for debuging
long_query_time = 1 # log queries as slow when their duration > 1 sec
innodb_buffer_pool_size = 1500M
innodb_log_buffer_size  = 80M
innodb_flush_log_at_trx_commit = 0 # I know it's not good for transaction security but it seemed to help