Mysql
加速 MariaDB?
我有一個 Wordpress Woocommerce 商店,它使用 WP All Import Pro 在 15 分鐘的 cronjob 計劃上執行自動導入。它通常每 15 分鐘嘗試從我們的供應商處更新 400 到 500 件商品。MariaDB 速度不夠快,無法在 15 分鐘內完成更新。任何幫助,將不勝感激!
伺服器資訊
Intel(R) Xeon(R) CPU E5-2630L v2 @ 2.40GHz
4 個中央處理器
8G記憶體
80G固態硬碟
更新
my.cnf
文件[client] port = 3306 socket = /var/run/mysqld/mysqld.sock [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0 [mysqld] 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/english skip-external-locking key_buffer = 4M max_allowed_packet = 10M thread_stack = 192K thread_cache_size = 8 open_files_limit = 30000 key_buffer_size = 20M myisam-recover = BACKUP max_connections = 45 max_user_connections = 15 query_cache_type = 1 query_cache_limit = 70M query_cache_size = 40M log_error = /var/log/mysql/error.log expire_logs_days = 10 max_binlog_size = 75M # # * InnoDB # innodb_buffer_pool_instances = 1 innodb_file_per_table = 1 innodb_buffer_pool_size = 820M innodb_log_file_size = 100M innodb_log_buffer_size = 1M join_buffer_size = 128M read_rnd_buffer_size = 4M max_allowed_packet = 20M tmp_table_size = 75M max_heap_table_size = 75M table_open_cache = 4500 thread_cache_size = 25 [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/
表定義:
CREATE TABLE `wp_posts` ( `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `post_author` bigint(20) unsigned NOT NULL DEFAULT '0', `post_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `post_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `post_content` longtext COLLATE utf8mb4_unicode_ci NOT NULL, `post_title` text COLLATE utf8mb4_unicode_ci NOT NULL, `post_excerpt` text COLLATE utf8mb4_unicode_ci NOT NULL, `post_status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'publish', `comment_status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'open', `ping_status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'open', `post_password` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', `post_name` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', `to_ping` text COLLATE utf8mb4_unicode_ci NOT NULL, `pinged` text COLLATE utf8mb4_unicode_ci NOT NULL, `post_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `post_modified_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `post_content_filtered` longtext COLLATE utf8mb4_unicode_ci NOT NULL, `post_parent` bigint(20) unsigned NOT NULL DEFAULT '0', `guid` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', `menu_order` int(11) NOT NULL DEFAULT '0', `post_type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'post', `post_mime_type` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', `comment_count` bigint(20) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), KEY `post_name` (`post_name`(191)), KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`), KEY `post_parent` (`post_parent`), KEY `post_author` (`post_author`) ) ENGINE=InnoDB AUTO_INCREMENT=135552 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE `wp_postmeta` ( `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `post_id` bigint(20) unsigned NOT NULL DEFAULT '0', `meta_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `meta_value` longtext COLLATE utf8mb4_unicode_ci, PRIMARY KEY (`meta_id`), KEY `post_id` (`post_id`), KEY `meta_key` (`meta_key`(191)) ) ENGINE=InnoDB AUTO_INCREMENT=3281739 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
這是我的 mysqltunner.pl 更新結果,您建議進行哪些調整?
[OK] Logged in using credentials from debian maintenance account. >> MySQLTuner 1.5.2 - Major Hayden <major@mhtx.net> >> Bug reports, feature requests, and downloads at http://mysqltuner.com/ >> Run with '--help' for additional options and output filtering [--] Skipped version check for MySQLTuner script [OK] Currently running supported MySQL version 10.0.20-MariaDB-0+deb8u1 [OK] Operating on 64-bit architecture -------- Storage Engine Statistics ------------------------------------------- [--] Status: +ARCHIVE +Aria +BLACKHOLE +CSV +FEDERATED +InnoDB +MRG_MyISAM [--] Data in InnoDB tables: 816M (Tables: 240) [--] Data in MyISAM tables: 2M (Tables: 95) [!!] Total fragmented tables: 13 -------- Security Recommendations ------------------------------------------- [OK] There is no anonymous account in all database users [OK] All database users have passwords assigned [--] There is 605 basic passwords in the list. -------- Performance Metrics ------------------------------------------------- [--] Up for: 14s (807 q [57.643 qps], 134 conn, TX: 3M, RX: 138K) [--] Reads / Writes: 100% / 0% [--] Binary logging is disabled [--] Total buffers: 1.1G global + 134.3M per thread (45 max threads) [OK] Maximum reached memory usage: 1.5G (18.68% of installed RAM) [!!] Maximum possible memory usage: 7.0G (89.16% of installed RAM) [OK] Slow queries: 0% (0/807) [OK] Highest usage of available connections: 6% (3/45) [OK] Aborted connections: 0.00% (0/134) [OK] Query cache efficiency: 23.6% (205 cached / 870 selects) [OK] Query cache prunes per day: 0 [OK] Sorts requiring temporary tables: 0% (0 temp sorts / 146 sorts) [OK] Temporary tables created on disk: 9% (20 on disk / 214 total) [OK] Thread cache hit rate: 97% (3 created / 134 connections) [OK] Table cache hit rate: 150% (187 open / 124 opened) [OK] Open file limit used: 0% (246/30K) [OK] Table locks acquired immediately: 100% (687 immediate / 687 locks) -------- MyISAM Metrics ----------------------------------------------------- [!!] Key buffer used: 19.1% (4M used / 20M cache) [OK] Key buffer size / total MyISAM indexes: 20.0M/561.0K -------- InnoDB Metrics ----------------------------------------------------- [--] InnoDB is enabled. [OK] InnoDB buffer pool / data size: 820.0M/816.9M [OK] InnoDB buffer pool instances: 1 [!!] InnoDB Used buffer: 15.80% (8293 used/ 52479 total) [OK] InnoDB Read buffer efficiency: 99.71% (1899945 hits/ 1905411 total) [!!] InnoDB Write buffer efficiency: 0.00% (0 hits/ 1 total) [OK] InnoDB log waits: 0.00% (0 waits / 1 writes) -------- AriaDB Metrics ----------------------------------------------------- [--] AriaDB is disabled. -------- Replication Metrics ------------------------------------------------- [--] No replication slave(s) for this server. [--] This is a standalone server.. -------- Recommendations ----------------------------------------------------- General recommendations: Run OPTIMIZE TABLE to defragment tables for better performance MySQL started within last 24 hours - recommendations may be inaccurate Reduce your overall MySQL memory footprint for system stability
嘗試使用 mysqltuner 腳本。
#Init tips #Check your logs size, numbers of log. #check database fragmentation #check your numbers of logs in dir. #set to size from key_buffer_size to 512M minimun [client] port = 3306 socket = /var/run/mysqld/mysqld.sock [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0 [mysqld] user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr ################### # Your can use personalized mount point (for example on a SSD Disk) ################### datadir = /var/lib/mysql tmpdir = /tmp ################### #Bad path? the dir is /usr/share/mysql/$LANG . Bad path cause redundand i/o ################### lc-messages-dir = /usr/share/mysql skip-external-locking ################### #MyISAM parameter? #if not use MyISAM set to 4M ################### key_buffer = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 open_files_limit=30000 ################### #minimun key_buffer_size to 512M. #Important ################### key_buffer_size = 32M ################### # Not use MyISAM parameter if your only use InnoDB ################### myisam_sort_buffer_size = 32M myisam-recover = BACKUP max_connections=100 max_user_connections = 50 query_cache_type = 1 query_cache_limit = 4M ################### #need more cache (4M cache top), >128MB ################### query_cache_size = 64M log_error = /var/log/mysql/error.log expire_logs_days = 10 max_binlog_size = 100M # Here you can see queries with especially long duration ################### # Remove slow log if you server is PRODUCTION. ################### slow_query_log_file = /var/log/mysql/mysql-slow.log slow_query_log = 1 long_query_time = 2 ################### # Generate big logs. CHECK YOUR LOG SIZE ################### log_queries_not_using_indexes # * InnoDB innodb_buffer_pool_instances=1 innodb_file_per_table=1 ################### # If your DB is tiny, 2GB is fat configuration. ################### innodb_buffer_pool_size = 2G innodb_log_file_size = 512M innodb_log_buffer_size = 1M join_buffer_size=128M read_rnd_buffer_size=8M max_allowed_packet = 20M tmp_table_size=256M max_heap_table_size=256M table_open_cache = 7500 thread_cache_size = 25
我查看了過多的參數…閱讀這篇文章(Percona):https ://www.percona.com/blog/2006/09/29/what-to-tune-in-mysql-server-after-installation/