1

I have question about how to connect local mysql db of another machine in same LAN. The scenario is we have 2 machines in LAN:

     machine 1 :   
     IP                 : 127.0.0.1    
     local website name :  https://127.0.0.1/demo_project1  
     mysql db name      :  demo1      

     machine 2 :   
     IP : 127.0.0.2  
     local website name :  https://127.0.0.2/demo_project2  
     mysql db name      :  demo2    

Can we do make db connection of https://127.0.0.1/demo_project1 to https://127.0.0.2/demo_project i.e demo2? It means both machine will working on same database.

Note :

  1. we have install on Xampp server on both machines.
  2. we can access https://127.0.0.2/demo_project2 of machine 2 from machine 1.
halfer
  • 19,824
  • 17
  • 99
  • 186
Swap.Y
  • 139
  • 1
  • 14
  • Do you mean that they use the same data files, or just that you see the same data on both machines? – Nigel Ren May 08 '17 at 06:50
  • You need xampp on both machines if each person works on his localhost apache server, but you need MySQL running on only one of them if you need to work on the same database. You connect to this DB from the remote machine by supplying the LAN IP address, the default MySQL server configuration should allow remote access but that could a a thing to take care of if there will be a problem with remote connection. – Picard May 08 '17 at 06:54
  • @NigelRen , yes i want to see same data on both machines. – Swap.Y May 08 '17 at 06:58
  • Hello @Picard , i have install xampp on both machines so both machine have apache and mysql server also. my question is very simple , i just want to make mysql server db connection of machine 2 from machine1. – Swap.Y May 08 '17 at 07:02
  • Then just check the IP address of the machine where the MySQL is running. I would do windows cmd and then ipconfig - you will see something like: `IPv4 Address. . . . .: 192.168.1.108`. Then enter this IP address as the IP address of the DB server in the remote machine DB configuration. – Picard May 08 '17 at 07:12
  • @Picard , i tried but i got this error " SQLSTATE[HY000] [1130] Host '127.0.0.1' is not allowed to connect to this MariaDB server" – Swap.Y May 08 '17 at 07:36
  • This is probably an error with the access rights - please take a look at these [answers](http://stackoverflow.com/questions/20353402/access-denied-for-user-testlocalhost-using-password-yes-except-root-user#answer-20353578) – Picard May 08 '17 at 07:37

1 Answers1

0

If the MySQL server is running in a machine which is connected to the same LAN where the second machine is connected, then you can access the MySQL server by specifying it’s IP address.

You can find the IP (IPv4 address), by executing ‘ifconfig’ in the ‘Command Prompt’ (from the Start menu).

You can sync the data between the servers by creating a mysql dump and executing the same dump one the other server. You can automate this process using several MySQL client tools like SQLyog, MySQL Workbench, etc. which provides data sync option between two databases.

  • hello I got such a error, Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'testdb'@'localhost' (using password: YES) in C:\xampp\htdocs\connection.php on line 7 Connection failed: Access denied for user 'testdb'@'localhost' (using password: YES) – Swap.Y May 12 '17 at 12:27