MySQL中的CPU利用率有时会非常高

MySQL中的CPU利用率有时会非常高,mysql,database-administration,Mysql,Database Administration,如何优化MySQL的CPU利用率有时会很高 这是我的my.ini文件 slow-query-log=1 long_query_time=10 server-id=1 max_connections=2000 table_open_cache=2000 tmp_table_size=391M thread_cache_size=10 key_buffer_size=512M read_buffer_size=64K read_rnd_buffer_size=256K innodb_addition

如何优化MySQL的CPU利用率有时会很高

这是我的my.ini文件

slow-query-log=1
long_query_time=10
server-id=1
max_connections=2000
table_open_cache=2000
tmp_table_size=391M
thread_cache_size=10
key_buffer_size=512M
read_buffer_size=64K
read_rnd_buffer_size=256K
innodb_additional_mem_pool_size=32M
innodb_flush_log_at_trx_commit=2
innodb_log_buffer_size=256M
innodb_buffer_pool_size=10G
innodb_log_file_size=512M
innodb_thread_concurrency=25
innodb_autoextend_increment=64
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=80
flush_time=0
join_buffer_size=256K
max_allowed_packet=256M
max_connect_errors=100
open_files_limit=4161
query_cache_type=1
sort_buffer_size=256K
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
query_cache_size = 2084M

建议在降低CPU利用率方面需要做任何修改?

建议考虑my.iN[myqLD]段rPS=每秒速率

在以root用户身份登录后,您可以验证这些动态全局变量是否适用于您的MySQL版本:

设置全局变量\名称=变量\值;注128K为128*1024,391M为391*1024*1024-动态更改不允许K&M

就在每天更改my.ini之前。如果您的请求被“只读”消息拒绝,请跳过该消息并通知我

# 20180904 1137  from  mysqlservertuning.com
# read_rnd_buffer_size=128K  # from 256K to reduce handler_read_rnd_next RPS
# innodb_io_capacity=1000  # from 200 to allow additional HD RD and WD RPS
# read_buffer_size=128K  # from 64K to reduce handler_read_next RPS
# max_connections=1000  # from 2000 because max_used_connections in 2 days was 244
# thread_cache_size=100  # from 10 to conserve CPU and reduce threads_created of 339 in 2 days
# max_heap_table_size=391M # from 16M to be = tmp_table_size and reduce created_tmp_disk_tables count
# innodb_lru_scan_depth=100  # from 1024 to reduce CPU busy every second see refman
# key_buffer_size=64M  # from 512M because only 11% used today
# innodb_change_buffer_max_size=15  # from 25 percent because less than 1% used 
# innodb_flushing_avg_loops=10  # from 30 to reduce flushing loop delay
每天,将您当前的my.ini保存在\history中,并使用带有日期的定时文件名,如20180904-1137-my.ini,以便快速返回上次使用my.ini

第一次,将此块(包括前导日期和我们的网站名称)复制到[mysqld]部分的末尾,并通过删除前导和空格字符启用每天一次更改,然后继续下一次更改

使用前导和空格键禁用先前命名的相同变量,以避免混淆。在5年内,您仍将拥有my.ini更改的历史记录和大致日期

通常每天只有一次变更,在进行下一次变更之前进行监控。如果更改似乎有害,请返回上次使用my.ini并让我们知道

# 20180904 1137  from  mysqlservertuning.com
# read_rnd_buffer_size=128K  # from 256K to reduce handler_read_rnd_next RPS
# innodb_io_capacity=1000  # from 200 to allow additional HD RD and WD RPS
# read_buffer_size=128K  # from 64K to reduce handler_read_next RPS
# max_connections=1000  # from 2000 because max_used_connections in 2 days was 244
# thread_cache_size=100  # from 10 to conserve CPU and reduce threads_created of 339 in 2 days
# max_heap_table_size=391M # from 16M to be = tmp_table_size and reduce created_tmp_disk_tables count
# innodb_lru_scan_depth=100  # from 1024 to reduce CPU busy every second see refman
# key_buffer_size=64M  # from 512M because only 11% used today
# innodb_change_buffer_max_size=15  # from 25 percent because less than 1% used 
# innodb_flushing_avg_loops=10  # from 30 to reduce flushing loop delay
期待您在实施后7天内将评论发布到mysqlservertuning.com,选择SHOP,选择您购买的商品-即使是免费的,请向下滚动到评论并添加您的评论。
发布评论不需要帐户登录。

您需要首先启用分析功能,并确定在负载较高时触发的查询的数量和类型。而且,有时还可以优化应用程序代码,以便在对象中重用查询结果,而不是再次查询相同的sql!在不知道您的服务器规格的情况下,这将是一个猜测游戏。服务器配置为:12核CPU,2.60 Ghz,68GB Ram。@WilsonHauck,我已经粘贴了全局状态、全局变量和My.ini文件,链接为:pastebin.com/t1E5NK6X,我没有任何MySQL调谐器report@Ranjanm您是否有任何SSD/NVME或所有旋转数据存储?感谢您对答案的友好回复,我将开始每天进行一次更改,我将开始监控系统并不断更新。感谢您对我的MySQL服务器的分析,现在MySQL服务器的CPU利用率越来越高。感谢您花了宝贵的时间与我一起优化Mysql服务器,从近15天。如果任何人面临MySQL问题,请访问[link],它有很多解决方案可以优化和检查您的MySQL问题。@Ranjanm非常荣幸能帮助您。请保持联系。