Extermly high MySQL CPU% - mysql

Any advice how to solve this problem? this is a new dedicated machine, the MySQL CPU usage strikes to 300% CPU usage
the command:
/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
[mysqld]
bind-address=127.0.0.1
performance-schema=0
init-connect='SET NAMES utf8mb4'
collation_server=utf8mb4_unicode_ci
character_set_server=utf8mb4
skip-character-set-client-handshake
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
innodb_buffer_pool_size=134217728
max_allowed_packet=268435456
open_files_limit=10000
innodb_file_per_table=1
slow_query_log=1
slow_query_log_file="/var/log/mysql-slow.log"
long_query_time = 2
machine is: Intel Xeon E3-1246V3, HDD SATA 2TB, 32GB DDR3
Centos 7.7, CPANEL installed

Related

question about mysql parameter max_connections

1.below is mysql config fule, /db/mysql/app/mysql/my.cnf
we set max_connections=4000
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
port=3306
socket=/db/mysql/data/mysqltmp/mysql.sock
[mysqld]
basedir=/db/mysql/app/mysql
datadir=/db/mysql/data/mydata
tmpdir=/db/mysql/data/mydata/tmp
bind-address=10.200.212.67
port=3306
wait_timeout=86400
server_id=2
user=mysql
socket=/db/mysql/data/mysqltmp/mysql.sock
skip-name-resolve
lower_case_table_names=1
default-storage-engine=InnoDB
max_heap_table_size=32M
thread_stack = 512K
key_buffer_size=256M
sort_buffer_size=2M
join_buffer_size=2M
innodb_file_per_table=1
innodb_open_files=2048
back_log=1000
max_connections=4000
open_files_limit=65535
table_open_cache=128
log_bin=mysql-bin
binlog_format=MIXED
expire_logs_days=7
log_error=/db/mysql/data/mydata/mysql-error.log
pid-file=/db/mysql/app/mysql/mysql.pid
slow_query_log=1
long_query_time=2
slow_query_log_file=/db/mysql/data/mydata/mysql-slow.log
max_allowed_packet=256M
binlog_cache_size=2M
innodb_buffer_pool_size = 8192M
innodb_write_io_threads=4
innodb_read_io_threads=4
innodb_thread_concurrency=0
innodb_purge_threads=1
innodb_flush_log_at_trx_commit=2
innodb_log_buffer_size=64M
innodb_log_file_size=512M
innodb_log_files_in_group=3
innodb_lock_wait_timeout=7200
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
gtid-mode=ON
enforce_gtid_consistency=1
log-slave-updates=1
2.when we do some application ,in rush hours ,
In addition, during the problem period of MySQL, the maximum number of connections is less than 1000, and the db max_connections setting is 4000
and when the connection is to 1000, the application will report timeout 30000ms. so app connet failed ,.
3.the quesiton is if there are any other hidden restrictions that cause the connection not allowed to more than 1000?

performance tuning of my sql in 12 GB ram with 21 Intel(R) Xeon(R) CPU E5-2620 0 # 2.00GHz

Hi are trying to optimize MySQL for a huge traffic web server, we are using Apache 2.4 , and MySQL 5.6 version.
We have put these parameters in MySQL configuration file
cat /etc/my.cnf
[mysqld]
skip-external-locking
key_buffer = 500M
max_allowed_packet=64M
max_connections = 2000
max_user_connections = 50000
wait_timeout=180
connect_timeout=120
table_open_cache=4096
table_definition_cache=4096
myisam_sort_buffer_size = 64M
thread_cache_size = 128
query_cache_size = 190M
query_cache_limit = 3M
open_files_limit=10000
log_error = /var/log/mysql/error.log
default-storage-engine=MyISAM
[mysqld]
log-bin=mysql-bin
binlog-do-db=******
server-id=1
[mysql]
no-auto-rehash
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
replicate-do-db=*****
auto_increment_increment = 2
auto_increment_offset = 1
replicate-same-server-id = 0
slave-skip-errors=all
[mysqld]
slave-skip-errors=1062
skip-slave-start
query_cache_type=1
[mysqld]
innodb_lock_wait_timeout=120
slave_compressed_protocol=1
query_cache_size = 190M
The QC is inefficient when it is big; limit to about 50M.
slave-skip-errors=1062
This is a flavor of "sweeping bugs under the rug".
default-storage-engine=MyISAM
passé.
key_buffer = 500M
If you do stick with MyISAM, and this server is running just MySQL, then use 1000M.
server-id=1
Make sure each server has a different value.
But that is only configuration. If you have slow queries, let's see them and try to improve them.

cpu usage is extremly high (1800%) due to mysql

I am having a 4 GB vps box. At any time there are not more than 40 visitors browsing 10-15 page simultaneously. Suddenly 2 days back server cpu usage touching almost 2000%. Strange thing is when i stop the apache, it still does not go down. below is the top command result.
PID USER PR NI VIRT RES SHR S CPU MEM TIME+ COMMAND
23644 mysql 15 0 12.7g 742m 6840 S 1812.0 18.1 1107:15 mysqld
14076 xyzaz 19 0 194m 16m 7348 S 7.1 0.4 0:00.22 php
14080 xyzaz 18 0 195m 17m 7276 S 6.5 0.4 0:00.20 php
i have troubleshooted every thing but no luck. I dont know it was working fine but suddenly how it changed to such a high value.
below is the output of my.cnf
[mysqld]
local-infile=0
max_connections=500
key_buffer_size=128M
myisam_sort_buffer_size=64M
join_buffer_size=2M
read_buffer_size=1M
sort_buffer_size=2M
max_heap_table_size=16M
table_cache=1800
thread_cache_size=384
interactive_timeout=25
wait_timeout=7200
connect_timeout=10
max_allowed_packet=268435456
max_connect_errors=100
query_cache_limit=4M
query_cache_size=128M
query_cache_type=1
tmp_table_size=64M
skip-name-resolve
innodb_buffer_pool_size=229M
default-storage-engine=MyISAM
innodb_file_per_table=1
[mysqld_safe]
open_files_limit = 6553
[mysqldump]
quick
max_allowed_packet=16M
[myisamchk]
key_buffer_size=64M
sort_buffer=64M
read_buffer=16M
write_buffer=16M
Any help is really appriciated

How should I config the my.ini(or my.cnf) file for mysql?

Thanks for taking your time to look at my question, and I hope that you can help me with this.
I have a Windows Server 2012 server, it has:
Memory : 3840MB Ram
Processor: Intel(R) Xeon(R) CPU E5-2680 v2 # 2.80GHz (2 CPUs), ~2.8GHz
But still mysql is going up to 100% cpu usage
I ran the MySQLInstanceConfig.exe configuration Wizard to help me config everything for mysql and this is the my.ini config file that it created:
[client]
port=3306
[mysql]
default-character-set=latin1
[mysqld]
The TCP/IP Port the MySQL Server will listen on
port=3306
basedir="C:/Program Files/MySQL/MySQL Server 5.5/"
datadir="C:/ProgramData/MySQL/MySQL Server 5.5/data/"
character-set-server=latin1
default-storage-engine=INNODB
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
max_connections=100
query_cache_size=0
table_cache=256
tmp_table_size=192M
thread_cache_size=8
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=384M
key_buffer_size=332M
read_buffer_size=64K
read_rnd_buffer_size=256K
sort_buffer_size=256K
* INNODB Specific options *
innodb_additional_mem_pool_size=14M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=7M
innodb_buffer_pool_size=643M
innodb_log_file_size=65M
innodb_thread_concurrency=8
But Something is still wrong, it's taking to much CPU
Try to use given configuration. This might help you.
[client]
port=3306
[mysql]
default-character-set=latin1
[mysqld]
The TCP/IP Port the MySQL Server will listen on
port=3306
basedir="C:/Program Files/MySQL/MySQL Server 5.5/"
datadir="C:/ProgramData/MySQL/MySQL Server 5.5/data/" #put basedir and datadir on different location
character-set-server=latin1
default-storage-engine=INNODB
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
max_connections=100
query_cache_size=10M
query_cache_limit=15M
table_cache=256
tmp_table_size=100M # Reduce temp table size it uses ram
thread_cache_size=16 #Increase this value
myisam_max_sort_file_size=100G
myisam_sort_buffer_size=384M
key_buffer_size=250M #Reduce this
read_buffer_size=64K read_rnd_buffer_size=256K
sort_buffer_size=256K
* INNODB Specific options *
innodb_additional_mem_pool_size=14M # SHOW INNODB STATUS will display the current amount used. set according to that
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=5M
innodb_buffer_pool_size=512M
innodb_log_file_size=65M
innodb_thread_concurrency=8

Optimal my.cnf recommendation

I'd like to ask anyone with a bit of experience on an opinion of my current my.cnf settings and what optimizations should be done.
Server specs are:
CPU: AMD Opteron™ 3280, 8 Cores, 8x 2.4 GHz
RAM: 16 GB DDR3
2x 2,000 GB SATA II-HDD, 7.2k - RAID 1 Software
Cloudlinux + Cpanel installed
Apache + Mysql 5.5 + NginxCP + eAccelerator
The current my.cnf file is:
[client]
port=3306
socket="/var/lib/mysql/mysql.sock"
[mysqld]
innodb_additional_mem_pool_size=16M
innodb_buffer_pool_size=10G
innodb_file_per_table=1
innodb_log_buffer_size=4M
innodb_flush_log_at_trx_commit=2
log-bin=mysql-bin
myisam_sort_buffer_size=64M
expire_logs_days=7
query_cache_size=128M
thread_cache_size=12
max_allowed_packet=15M
skip-federated
table_definition_cache=2048
local-infile=0
table_cache=8192
max_connections=60
read_buffer_size=2M
slow_query_log=1
slow_query_log_file="/var/log/slow_queries.log"
thread_concurrency=16
sort_buffer_size=2M
port=3306
join_buffer_size=16M
key_buffer_size=600M
query_cache_limit=10M
socket="/var/lib/mysql/mysql.sock"
skip-external-locking
query-cache-type=1
long_query_time=5
default-storage-engine=InnoDB
tmp_table_size=384M
max_heap_table_size=384M
[myisamchk]
read_buffer=2M
key_buffer=256M
sort_buffer_size=256M
write_buffer=2M
[mysqldump]
max_allowed_packet=16M
DBAs recommended to use the Percona Wizard first o all https://tools.percona.com/wizard
Secondly follow this guide: http://www.percona.com/blog/2014/01/28/10-mysql-settings-to-tune-after-installation/