简体   繁体   中英

PHP How to allow mysql to connect from remote server

I have 2 VPS running on centos 7. VPS #1: 192.164.64.76 VPS #2: 192.164.64.19

ON VPS #2 I have a database named DBASE. I need to connect to it from remote server(VPS #1). I have tried everything and still MySQL does not allow me to connect. I need a step by step guide to show me how to solve my issue. This is my PHP code(I put it on VPS #1)

<?php 
    DEFINE ('DB_USER_1', 'remoteuser');
    DEFINE ('DB_PASSWORD_1', 'dsdafdf4323fe');
    DEFINE ('DB_HOST_1', '192.164.64.19');
    DEFINE ('DB_NAME_1', 'dbase');

    $pol1 = @mysql_connect (DB_HOST_1, DB_USER_1, DB_PASSWORD_1)
OR die ('Nie mogłem się połączyć: ' . mysql_error() );
    @mysql_select_db (DB_NAME_1) OR die ('Nie mogłem wybrać bazy danych: ' . mysql_error() );
?>

Gives me error:

Can't connect to MySQL server on '192.164.64.19' (13)

DEFINE ('DB_USER_1', 'remoteuser');
DEFINE ('DB_PASSWORD_1', 'dsdafdf4323fe');
DEFINE ('DB_HOST_1', '192.164.64.19');
DEFINE ('DB_NAME_1', 'dbase');

$pol1 = mysqli_connect(DB_HOST_1, DB_USER_1, DB_PASSWORD_1)
OR die ('Nie mogłem się połączyć: ' . mysql_error() );
mysqli_select_db(DB_NAME_1) OR die ('Nie mogłem wybrać bazy danych: ' . mysql_error() );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM