MySQL Timeout in XAMPP - php

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

Related

Slow UPDATE queries after migrate to new server

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.

Tuning mysql, mysqltuner warnings

I'm running a Magento website with 100 visitor/hour and have 64GB RAM with an Intel Core i7 CPU. When I run mysqltuner, I receive the message "MySQL's maximum memory usage is dangerously high".
I need help with tuning MySQL to fit my needs, and to clear the warning.
Here is my.cnf file :
key_buffer = 32M
max_allowed_packet = 16M
thread_stack = 256K
thread_cache_size = 100
table_open_cache = 4000
table_definition_cache = 8192
tmp_table_size = 512M
max_heap_table_size = 512M
innodb_buffer_pool_instances = 24
innodb_flush_log_at_trx_commit = 0
innodb_read_io_threads = 64
innodb_write_io_threads = 64
innodb_io_capacity = 50000
innodb_flush_method = O_DIRECT
innodb_file_per_table
innodb_additional_mem_pool_size = 16M
transaction-isolation = READ-COMMITTED
innodb_support_xa = 0
innodb_commit_concurrency = 8
innodb_old_blocks_time = 1000
innodb_lock_wait_timeout = 120
innodb_buffer_pool_size = 40G
thread_concurrency = 10
max_connections = 64
innodb_thread_concurrency = 18
thread_cache_size = 64
table_cache = 2000
query_cache_type = 1
query_cache_size = 128M
query_cache_limit = 3M
key_buffer_size = 8G
sort_buffer_size = 64M
read_buffer_size = 64M
read_rnd_buffer_size = 64M
join_buffer_size = 128M
What can I do to make the mysqltuner warning disappear?
Suggestions to consider for your my.cnf-ini [mysqld] section
Lead with # the following or REMOVE them will allow MySQL defaults
to be used and go a long way toward eliminating the message.
sort_buffer_size = 64M
read_buffer_size = 64M
read_rnd_buffer_size = 64M
join_buffer_size = 128M
You will find response time is much better.
Please post complete TEXT of MySQL Tuner report.
Additional suggestions Jul 14, 2018
innodb_buffer_pool_instances=8 # from 24 minimize overhead
innodb_lru_scan_depth=128 # from 1024 to conserve CPU every second
For additional assistance, check my profile, clk Network Profile for contact info. Thanks

mysql 5.7.9 : windows log: Got an error reading communication packets

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

mysqli_query() : "mysql server has gone away" and "Error reading result set's header" on uploads >3M

I have both error in the title when I'm trying to upload a file bigger then about 3 megabytes to my server.
Here is what I tried in my.ini:
# The MySQL server
[wampmysqld]
SET SESSION wait_timeout=28800
SET GLOBAL wait_timeout=28800
interactive_timeout=3000
wait_timeout=3000
mysql.connect_timeout = 1000
port = 3306
socket = /tmp/mysql.sock
key_buffer_size = 16M
max_allowed_packet = 100M
sort_buffer_size = 8K
net_buffer_length = 512K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
basedir=c:/wamp/bin/mysql/mysql5.6.17
log-error=c:/wamp/logs/mysql.log
datadir=c:/wamp/bin/mysql/mysql5.6.17/data
[mysqld]
SET SESSION wait_timeout=28800
SET GLOBAL wait_timeout=28800
max_allowed_packet = 100M
interactive_timeout=3000
wait_timeout=3000
port=3306
explicit_defaults_for_timestamp = TRUE
and in php.ini:
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 500M
The table containing the file has longblob data type for the content. I still have these errors after these changes. What should I do?

How to set memory limit in my.cnf file [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How to set memory limit in my.cnf file. I tried with memory_limit = 64M . But its showing error while restarting MYSQL server. Any one please help...
my.cnf
[mysqld]
datadir=/home/mysql/
tmpdir=/home/mysqltmp
#max_connections = 175 #was 175
max_connections = 80
#max_connect_errors = 350 #was 250
max_connect_errors = 250
safe-show-database
skip-locking
key_buffer = 1024M # was 128M
max_allowed_packet = 6M
myisam_sort_buffer_size = 64M
#old settings, for 900 ish max maxconn
#sort_buffer_size = 32M
#read_buffer_size = 32M
#read_rnd_buffer_size = 32M
sort_buffer_size = 5M
read_buffer_size = 5M
read_rnd_buffer_size = 5M
query_cache_size= 1024M
query_cache_limit= 16M
max_heap_table_size = 128M
tmp_table_size = 128M
thread_concurrency = 16
wait_timeout = 10
innodb_file_per_table
innodb_log_file_size = 10485760
open_files_limit = 8192
low_priority_updates = 1
#log_slow_queries = /var/log/mysql_slow.log
#log_queries_not_using_indexes = 1
#slow_queries_log_file = /var/log/mysql_slow.log
memory_limit = 64M
# who set these? these are NOT memory settings, but rather integer settings.
#table_cache = 1024M
#thread_cache_size = 8M
table_cache = 512
thread_cache_size = 8
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
There is no such variables like memory_limit in MySQL my.cnf file. You can add variables only from MySQL server system variables. Read this How Mysql uses memory
It depends on RAM size of your MySQL server. You can configure your my.cnf file accordingly based on following basic formula for MySQL memory requirement calculation:
key_buffer_size + (read_buffer_size + sort_buffer_size) * max_connections = K bytes of memory
you may need to configure these basic parameters.
Sample variables from my.cnf file:
#MyISAM
key_buffer_size = 8G
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 2M
myisam_sort_buffer_size = 2M
join_buffer_size = 2M
#Innodb
innodb_buffer_pool_size = 16G
innodb_additional_mem_pool_size = 2G
innodb_log_file_size = 1G
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 30
innodb_file_format=barracuda
There is no memory_limit limit setting in MySQL. The only way you can manage or limit the memory usage of MySQL is to lower the settings for cache, buffer and pool sizes(the exact settingnames depend on what storage engine you are using.
Some settings that apply for the MyISAM engine (the default engine) is:
table_cache=1024
record_buffer=1M
sort_buffer_size=2M
read_buffer_size=2M
read_rnd_buffer_size=2M
myisam_sort_buffer_size=64M
thread_cache_size=128
query_cache_limit=1M
query_cache_size=64M
query_cache_type=1
For InnoDB you have:
innodb_buffer_pool_size = 256M
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 64M
innodb_log_buffer_size = 8M
If you are looking to change the memory limit in PHP that line(memory_limit = 64M) should be in the php.ini file, not my.cnf which is the configuration file for MySQL.

Categories