Problem with mysqli connect

This is strange. I have 2 centos box, prod (192.168.0.1) and vm (192.168.0.30). The Mysql database is located on prod. The application is on vm. From vm if I type

mysql -u user -p -h 192.168.0.1 -D mydb

it connects perfectly, so the port is open and listened on prod but in the application, I do

$db=new mysqli('192.168.0.1','user','mypass','mydb');

and i get

Warning: mysqli::mysqli() [function.mysqli-mysqli]: (HY000/2003): Can't connect to 
MySQL server on '192.168.0.1' (13) in /var/www/vhosts/myapp/httpdocs/dstest.php 
on line 123

Both blocks have exactly the same versions of php, mysql, mysql.so, mysqli.so

Any tips?

PS This also happens if I try $ db = new mysqli ('127.0.0.1', ... BUT NOT if I try $ db = new mysqli ('localhost', ...

in case this helps, here is my.cnf on prod:

[mysqld]
set-variable=local-infile=0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

max_connections = 500
max_user_connections = 150

key_buffer = 2048M

query_cache_limit=4M
query_cache_size=64M
table_cache=2048
tmp_table_size=64M
max_heap_table_size = 256M

# users buffers
sort_buffer_size=2M
read_buffer_size=2M
read_rnd_buffer_size=1M

max_allowed_packet=16M

thread_cache=16
thread_concurrency=8
thread_cache_size=128
innodb_buffer_pool_size = 128M
myisam_sort_buffer_size = 128M

wait_timeout = 240
interactive_timeout = 240
max_allowed_packet=32M

[mysql.server]
user=mysql
basedir=/var/lib

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
+3
source share
2 answers

Check here . It is very similar to your problem.

: :

SQLSTATE[HY000] [2003] Can’t connect to MySQL server on β€˜xxx.xxx.xxx.xxx’ (13)

, Google , , PHP script MySQL SQLSTATE [HY000] [2003] MySQL 'xxx.xxxx.xxx.xxx' (13)

, , - Zend Framework, , - SELinux PHP, - Apache. (13) " ", , .

, root setsebool -P httpd_can_network_connect=1 .

, , - , , , .

+18

, :

$db=new mysqli('localhost','user','mypass','mydb'); 

$db=new mysqli('192.168.0.1','user','mypass','mydb');

.

0

Source: https://habr.com/ru/post/1758035/


All Articles