Connect to MySQL on another server

I have two servers (virtual machines - I can remotely connect to them) - server 1 and server 2.

On server 1, I save my web pages, and on server 2 I store databases.

I am currently trying to connect to a database on server 2 from server 1.

Here is my PHP code:

<?php
            $dbhost = 'xxx.xx.xx.xx:xxxx';
            $dbuser = 'xxxxxx';
            $dbpass = 'xxxxxx';

            $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql' . mysql_error());


            $dbname = 'database';
            mysql_select_db($dbname);
?>

This is the error message I get when I try to connect:

Access denied for user 'xxxxxx'@'server1' (using password: YES)

I found it a little perplexing that it says @ server1, given that I am trying to connect to server 2. Can anyone suggest any ideas?

thank

PS: They are both on Windows 2008

+3
source share
4 answers

MySQL , . , ( localhost), .

, 'xxxxxx' 'server1'. "xxxxxx" ( "%" ). , ( "server1" ) ( "%.mydomain.com" "144.155.166.0/255.255.255.0" ), .

MySql . http://dev.mysql.com/doc/refman/5.0/en/connection-access.html.

+3

" " xxxxxx "@" server1 ", 1 2. server2, 1 ( : server1);

+2

+2

'xxxxxx' @'%'. . @'%' , .

+2

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


All Articles