Oct 03 2016

WordPress & MySql…

Category: English posts,TechnicalIuliana @ 23:28

… is a recipe for disaster. Once every few weeks I get this:

Error establishing a database connection.

Today I tried another two tricks:
1. Adding the following configurations to the Apache httpd.conf file.

StartServers 3
MinSpareServers 3
MaxSpareServers 5
MaxRequestWorkers 25
MaxConnectionsPerChild 0

2. Configurating MySQL like this in /etc/my.cnf
# Disabling symbolic-links is recommended to prevent assorted security risks
# Set internal buffers, caches and stacks very low
key_buffer = 16K
max_allowed_packet = 16K
table_cache = 1
sort_buffer_size = 16K
read_buffer_size = 16K
read_rnd_buffer_size = 1K
net_buffer_length = 1K
thread_stack = 16K
# Don't listen on a TCP/IP port at all.
# Will still work provided all access is done via localhost
server-id = 1
# Set the query cache low
query_cache_limit = 1048576
query_cache_size = 1048576
query_cache_type = 1
# Set various memory limits very low, disable memory-hogging extras
max_allowed_packet = 16K
key_buffer = 16K
sort_buffer_size = 16K
key_buffer = 16K
sort_buffer_size = 16K

I’ll come back here with an update, in case I managed to make the bloody damn thing stop from crashing.

[Update]: Well, the database no longer crashed, but the ec2 instance did. So I had to terminate it and create a new one. And of course I did not remember anything I did to keep it working so I cam back to this post. And I just found out that the innodb_buffer_pool_size property value depends on the machine you are on. If it is too big, the connection pool will require too much memory and if you do not have that memory, Mysql will still crash. So I just switched to the smallest value that I think it could be necessary for my blog to be accessed by my 50 readers per day: 10MB. And aside from this I modified my instance to add some swap. You can find a really useful tutorial here, I used the first option to create the file in the current file system.


Tags: , ,

Leave a Reply