Mysql – Couldn’t connect to databasee

connectivitylinuxMySQL

I have a dedicated webserver and a dedicated database server.

Often, I get errors connecting to the database server

couldn't connect to database

Here is my current /etc/my.cnf configuration file

[mysqld]
local-infile=0
innodb_file_per_table=1
max_allowed_packet = 100M

log-slow-queries=/var/log/slow.log

open_files_limit=7306
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
nice = -10

How can I increase the timeout connect for the database server?

Best Answer

Actually I do not think this is something you would want to change under nearly any circumstances. You should not fix the symptom, but should find out the problem.

Does the mysql log contains information about aborted connections? Does the syslog of that server contain information which might be relevant? Do you run a more or less decent version of mysql? (At least the most current minor version.) Have you checked if the database server runs out of resources (e.g. RAM, because swapping is really bad for any DB server)? Have you compared the number of connections your webserver maximally issues simultaneously to the db server and the number of connections your db server is processing in parallel from its configuration file?

Have you tried pinging the database server from the web server for a long period of time? Does the ping slows down (or gets lost) too, when the error message pops up in your application?

You should check all that before you change anything in timeouts.