I have moved my website to new faster dedicated server (64GB RAM, CPU 4c/8t 3.7GHz in OVH). The problem is that now my site works even slower, not faster.
I figured out that this is because of slow UPDATE queries to my mysql. I have read many topics, tried many configurations without any luck. Mysql config is almost default so I don't understand why it is not working. This is not overload because I turned off website and make test from phpmyadmin - same results.
So I have this query in phpmyadmin and execute this few times on both server. Tables (InnoDB) and data are exactly the same.
UPDATE `user` SET `last_date` = "2017-02-05 03:40:50" WHERE `id`=3;
Times on new server:
0.0553 s
0.0265 s
0.0229 s
0.0369 s
0.1579 s <---
0.0191 s
Times on old server:
0.0024 s
0.0042 s
0.0015 s
0.0015 s
0.0015 s
0.0012 s
New server software: Debian 8, Mysql 5.5.31, Apache 2.2.16, PHP 7.1
Old server software: Debian 6, Mysql 5.5.31, Apache 2.2.16, PHP 5.3
I've tried copy entire my.cnf from old to new but results are the same. So why the same config works great on old system, but not on new fresh one?
New server my.cnf
port = 3306
socket = /var/run/mysqld/mysqld.sock
socket = /var/run/mysqld/mysqld.sock
nice = 0
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
skip-external-locking
bind-address = 127.0.0.1
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
myisam-recover = BACKUP
query_cache_limit = 1M
query_cache_size = 0
general_log_file = /var/log/mysql/mysql.log
general_log = 0
slow_query_log_file = /var/log/mysql/mysql-slow.log
slow_query_log = 1
long_query_time = 2
expire_logs_days = 10
max_binlog_size = 100M
innodb_buffer_pool_size = 16G
max_connections = 2048
skip_name_resolve = 1
quick
quote-names
max_allowed_packet = 16M
key_buffer = 16M
Old server my.cnf
port = 3306
socket = /var/run/mysqld/mysqld.sock
socket = /var/run/mysqld/mysqld.sock
nice = 0
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /dev/shm
bind-address = 0.0.0.0
key_buffer = 128M
max_allowed_packet = 40M
thread_stack = 192K
thread_cache_size = 8
myisam-recover = BACKUP
max_connections = 1000
table_cache = 4096
thread_concurrency = 10
max_heap_table_size = 48M
tmp_table_size = 48M
general_log_file = /var/log/mysql/mysql.log
general_log = 1
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 2
expire_logs_days = 10
max_binlog_size = 100M
innodb_buffer_pool_size = 4500M
quick
quote-names
max_allowed_packet = 16M
key_buffer = 16M
Why is this happening?
Edit:
I have tried also:
Make query directly from mysql terminal.
Restart apache after my.cnf change.
PHP 5.
Related
MySQL showing very high CPU usage. like over 200% sometime.
I had slow query log on. and slow query time set to 1s.
there is not any slow query.
I am using code igniter PHP.
my my.cnf file :
[mysqld]
innodb_io_capacity=2000
innodb_read_io_threads=32
innodb_write_io_threads=32
innodb_log_buffer_size=250M
innodb_thread_concurrency=0
innodb_buffer_pool_size=1000M
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
skip-external-locking
##
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
#
# * Fine Tuning
#
innodb_buffer_pool_size = 12G
key_buffer_size = 1G
max_allowed_packet = 256M
thread_stack = 192K
thread_cache_size = 100
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
max_connections = 300
#innodb_buffer_pool_instances=8
#innodb_read_io_threads=8
#innodb_write_io_threads=8
#open_files_limit = 1024
#table_open_cache = 400
server_id = 2
bind-address = 0.0.0.0
log_bin = /var/log/mysql/mysql-bin.log
log_bin_index = /var/log/mysql/mysql-bin.log.index
relay_log = /var/log/mysql/mysql-relay-bin
relay_log_index = /var/log/mysql/mysql-relay-bin.index
expire_logs_days = 10
max_binlog_size = 100M
log_slave_updates = 1
auto-increment-increment = 2
auto-increment-offset = 2
replicate-ignore-db=phpmyadmin
replicate-ignore-db=mysql
skip-name-resolve
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit=0
query_cache_size=0
sort_buffer_size = 2M
join_buffer_size = 128K
read_buffer_size = 128K
read_rnd_buffer_size=256K
what can I do to reduce CPU usage?
Is there any way to find which queryes are causing high cpu usage o
there is not any slow query
There aren't any slow queries, or there aren't any slow queries showing in the log? I think your first prt of call would be to check if the query logging is working as you expect. This can be done easily using discretionary locks without adding additional load on the system.
Assuming that there really are no queries taking over 1 second, then the load arises fro lots of queries taking less than 1 second. You need to capture them all to identify and prioritize your tuning efforts. But you might start by enabling the query cache (which you have disabled for some reason).
I updated the MySQL version the correct way, however when clicking to start running it from the error and does not start.
Now I followed following points to install the same:
Install MySQL to C:\TEMP.
Make old installation folder to mysql_old.
copy the following folders "bin, include, lib, share, support-files" to xamp\mysql\ folder. I didn't copy the data folder
Copied my.ini file from old installation to new installation in xamp\mysql\bin\ folder
Copied the old data folder to new MySQL folder
Report Xampp
11:53:07 [mysql] Error: MySQL shutdown unexpectedly.
11:53:07 [mysql] This may be due to a blocked port, missing dependencies,
11:53:07 [mysql] improper privileges, a crash, or a shutdown by another method.
11:53:07 [mysql] Press the Logs button to view error logs and check
11:53:07 [mysql] the Windows Event Viewer for more clues
11:53:07 [mysql] If you need more help, copy and post this
11:53:07 [mysql] entire log window on the forums
Log MySQL Error:
2017-12-15T13:53:02.700418Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-12-15T13:53:02.700418Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2017-12-15T13:53:02.700418Z 0 [Note] c:\xampp\mysql\bin\mysqld.exe (mysqld 5.7.20) starting as process 7764 ..
my.ini
# The following options will be passed to all MySQL clients
[client]
# password = your_password
port = 3306
socket = "C:/xampp/mysql/mysql.sock"
# The MySQL server
[mysqld]
port= 3306
socket = "C:/xampp/mysql/mysql.sock"
basedir = "C:/xampp/mysql"
tmpdir = "C:/xampp/tmp"
datadir = "C:/xampp/mysql/data"
pid_file = "mysql.pid"
# enable-named-pipe
key_buffer = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log_error = "mysql_error.log"
# Change here for bind listening
# bind-address="127.0.0.1"
# bind-address = ::1 # for ipv6
# Where do all the plugins live
plugin_dir = "C:/xampp/mysql/lib/plugin/"
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
# commented in by lampp security
#skip-networking
skip-federated
# Replication Master Server (default)
# binary logging is required for replication
# log-bin deactivated by default since XAMPP 1.4.11
#log-bin=mysql-bin
# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1
# Comment the following if you are using InnoDB tables
#skip-innodb
innodb_data_home_dir = "C:/xampp/mysql/data"
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = "C:/xampp/mysql/data"
#innodb_log_arch_dir = "C:/xampp/mysql/data"
## You can set .._buffer_pool_size up to 50 - 80 %
## of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
## Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
## UTF 8 Settings
#init-connect=\'SET NAMES utf8\'
#collation_server=utf8_unicode_ci
#character_set_server=utf8
#skip-character-set-client-handshake
#character_sets-dir="C:/xampp/mysql/share/charsets"
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[isamchk]
#key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
Maybe try to start your mysql on diffrent port for example 3307
I'm using the mysql 5.7.9-log on windows2012 as service.
Then connect and query to the mysql with .netconnector or phpmysqli
Got every query this information on windows event :
Aborted connection 2481 to db: 'dbdb' user: 'myuser' host: '127.0.0.1'
(Got an error reading communication packets)...
but query successfully applied
don't happened on mysql5.6
my my.ini file:
[mysqld]
port= 3306
basedir = "C:/KAPPS/mysql/"
tmpdir = "C:/KAPPS/mysql/tmp"
datadir = "C:/KAPPS/mysql/data"
plugin_dir = "C:/KAPPS/mysql/lib/plugin/"
server-id = 1
pid_file = "mysql.pid"
log_error = "mysql_error.log"
#bind-address=0.0.0.0 # I tried
# custom config
tmp_table_size=2G
max_heap_table_size=2G
event_scheduler=ON
wait_timeout=10000
max_allowed_packet = 10M
skip_name_resolve
group_concat_max_len=15360
slow_query_log=ON
slow_query_log_file="slow_queries.log"
# performance
innodb_buffer_pool_size = 512M
sort_buffer_size = 8M
read_rnd_buffer_size = 8M
join_buffer_size = 256M
query_cache_size = 256M
key_buffer_size=512M
innodb_buffer_pool_size = 1G
sql_mode=
Any suggestion ?
edit:
this my.ini line solved my problem:
log_error_verbosity=1
ref this link
I have XAMPP installed on Microsoft Windows Server 2003. I have a PHP application in xampp/htdocs directory. I have started the Apache and MySQL instances.
I have noticed that every morning, my application gives a MySQL Error when I try to log in to my application. This is fixed after restarting MySQL instance in XAMPP control panel on the server. I think this may be due to timeout. How do I prevent timeout?
This is the my.ini:
[client]
port = 3306
socket = "D:/xampp/mysql/mysql.sock"
[mysqld]
port= 3306
socket = "D:/xampp/mysql/mysql.sock"
basedir = "D:/xampp/mysql"
tmpdir = "D:/xampp/tmp"
datadir = "D:/xampp/mysql/data"
pid_file = "mysql.pid"
key_buffer = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log_error = "mysql_error.log"
plugin_dir = "D:/xampp/mysql/lib/plugin/"
skip-federated
server-id = 1
innodb_data_home_dir = "D:/xampp/mysql/data"
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = "D:/xampp/mysql/data"
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
This is the error I come across every morning before restarting MySQL on XAMPP:
Warning: mysql_pconnect(): MySQL server has gone away in D:\MyApplication\mysql.inc on line 432
Warning: mysql_pconnect(): Link to server lost, unable to reconnect in D:\MyApplication\mysql.inc on line 432
Fatal Error: Failed to connect to database
I manage a file sharing website (like mediafire,hotFile, etc.) and there is a problem when people try to download from one of the servers.
It goes like this: I have one main server - there I have the mysql database and the website himself, and I have more servers to host the files.
The download process goes like this: user get a link to the outside server. This page connect remotely to the main server and make querys with the database. After the querys, the download get started.
Now, all of the downloads works fine, except from one of the servers. The weirdest thing is that sometimes the download from this server is works, and sometimes not!
It's about 70% of times the download from the problematic server is works, and 30% of times the download isn't works.
When the download isn't working the error message is:
Connect failed: Lost connection to MySQL server at 'reading authorization packet', system error: 0
The my.cnf looks like this:
[mysqld]
skip-name-resolve
bulk_insert_buffer_size = 8M
concurrent_insert = 2
connect_timeout = 10
default-storage-engine = MyISAM
innodb_buffer_pool_size=16M
interactive_timeout = 35
join_buffer_size = 2M
key_buffer_size = 192M
local-infile=0
log-error=/var/log/mysql/error.log
log-slow-queries
log-slow-queries=/var/log/mysql/mysql-slow.log
long_query_time=1
max_allowed_packet = 32M
max_connections = 3000
max_heap_table_size = 256M
max_user_connections= 400
max_write_lock_count = 8
myisam_max_sort_file_size = 256M
myisam_sort_buffer_size = 64M
open_files_limit=128K
query_alloc_block_size = 65536
query_cache_limit = 16M
query_cache_size = 128M
query_cache_type = 1
query_prealloc_size = 262144
range_alloc_block_size = 4096
read_buffer_size = 2M
read_rnd_buffer_size = 1M
sort_buffer_size = 2M
table_cache = 48K
thread_cache_size = 512
tmp_table_size = 256M
transaction_alloc_block_size = 4096
transaction_prealloc_size = 4096
wait_timeout = 100
max_connect_errors = 5000
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
How can I fix the problem?
Thank you very much, and sorry for my English.