1
I have two servers with different purposes, one being a webserver running apache and php 5.3, and the other is a Mysql database server. The first uses the database in the second 24 hours a day, 7 days a week.
The problem is that we recently started having errors a few times a day, where PHP applications return the following error message to our users:
Can't connect to MySQL server on 'IP_DO_BANCO_DE_DADOS' (4)
We have several PHP applications in our Webserver, and the connection is executed according to the framework used. One of our (legacy) applications that makes no use of any framework, and therefore uses PHP natively to connect to Mysql, proceeds as follows:
function AbreBD($mysqli = false) {
global $conexao, $selecao, $conexao_mysqli;
$servidor = '192.168.101.20:3306';
$usuarioBD = 'user';
$senhaBD = 'user';
$conexao = mysql_connect($servidor, $usuarioBD, $senhaBD);
$selecao = mysql_select_db("bioextratus", $conexao);
if ($mysqli) {
$conexao_mysqli = new mysqli($servidor, $usuarioBD, $senhaBD, "bioextratus");
}
}
Remembering that the above code is for a legacy application, and so it still uses the mysql driver instead of mysqli. Even in our most modern frameworks applications the problem also occurs.
I believe the problem is the configuration of Mysql or network problem, although the Mysql service is always available, as well as communication between the two servers over the network.
The contents of the Mysql file my.cnf from our database server (without the comments):
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
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
skip-external-locking
explicit_defaults_for_timestamp = false
open_files_limit = 102400
bind-address = 0.0.0.0
key_buffer = 16M
key_buffer_size = 512M
innodb_buffer_pool_size = 256M
innodb_additional_mem_pool_size = 8M
max_allowed_packet = 16M
thread_stack = 196K
thread_cache_size = 8
myisam-recover-options = BACKUP
query_cache_limit = 64M
query_cache_type = 1
query_cache_size = 256M
max_connections = 1024
max_user_connections = 0
sort_buffer_size = 2M
join_buffer_size = 1M
tmp_table_size = 64M
max_heap_table_size = 18M
log_error = /var/log/mysql/error.log
expire_logs_days = 10
max_binlog_size = 100M
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[isamchk]
key_buffer = 12M
Are the two servers from you or a "Provider"? gives a look at the Mysql log to see if it detects problem, ie, whether PHP can not "talk" with Mysql or whether it is Mysql that does not understand what PHP says. (Note: I don’t quite understand the idea of mysql instead of mysqli...)
– Peter