Connect to mysql on another server

I am trying to connect to mysql database server from another server. The following are the configurations on both servers.

Server 1: I installed xampp with php and apache services and it has the following ip 172.x1.x1.x1

Server 2: I installed mysql and it has the following ip 172.x1.x1.x2.

the following script connection that I use to connect to the database

<?php
    //Database connection constants
    define("DATABASE_HOST", "172.x1.x1.x2");
    define("DATABASE_USERNAME", "root");
    define("DATABASE_PASSWORD", "");
    define("DATABASE_NAME", "management");
?>

The above script is in a file called app_config.php and is located on server 1. The next script is in a file called connect.php and it is also on server 1

<?php
require 'app_config.php';
$connect_error = 'Sorry we\'experiencing connection problems.';
$table_error = 'Table not found';
mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD)
or die($connect_error);

mysql_select_db (DATABASE_NAME) or die ($ table_error); ? > now when I try to connect, I get the following error:

: mysql_connect() [function.mysql-connect]: 'hr1.saqa.co.za' MySQL C:\xampp\htdocs\scripts\functions\database\connect.php 4

: undefined handle_error() C:\xampp\htdocs\scripts\functions\database\connect.php 5

, , .

+3
2

php/apache, 172.x1.x1.x2 mysql-php.

, mysql root . mysql- root . 1.

, mysql.user.

mysql> select Host,User from user where User = "root";
+------------+------+
| Host       | User |
+------------+------+
| 127.0.0.1  | root |
| ::1        | root |
| localhost  | root |
| sgeorge-mn | root |
| %          | root |
+------------+------+
4 rows in set (0.01 sec)

% .

, mysql :

mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'your_password';
+3

1) , MySQL.

2) , MySQL.

+2

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


All Articles