To synchronize the local database and web server database in MySql

I use PHP and Mysql to develop the application. we have two copies of the database, one on the local server (i.e. at our end) and one on the web server. we want to synchronize both databases so that any changes made to the local database are also reflected in the web server database. is it possible ?? We are currently using PHP scripts to do this. It takes too much time and also unreliable. What can be done to make MySQL internally run all the updates and logic?

NOTE. - Our local server runs on Windows, and the web server is based on Unix, and we do not use the command line to access both machines, in fact on both sides, in which we use a PHP application to update and store data (i.e. add new or update data)

+3
source share
3 answers

MySQL , , . -. , ( , ), ( , ) ( , ).

+2

edit: , - .

MySQL; , -.

0

- MySql, . SQL

1). Here you need two computers if you do it offline for testing, and the first PC will be your MASTER, and the other will act as SLAVE.

2). Check the IP address of your computers.

3). I run it on Localhost with these two next computers

Machine-1: - 192.168.1.20

Machine-2: - 192.168.1.21

and then open Mysql and start typing these commands on both machines as follows

---------------- Commands for SERVER-1 ------------------
IP-Address e.g. = 192.168.1.20
---------------------------------------------------------

CREATE USER 'server1'@'%' IDENTIFIED BY '12345';

GRANT REPLICATION SLAVE ON *.* TO 'server1'@'%' IDENTIFIED BY '12345';

FLUSH TABLES WITH READ LOCK;

SHOW MASTER STATUS;

UNLOCK TABLES;


---------------- Commands for SERVER-2 -----------------
IP-Address e.g. = 192.168.1.21
--------------------------------------------------------

STOP SLAVE;

RESET SLAVE;

CHANGE MASTER TO
MASTER_HOST = '192.168.1.20',
MASTER_USER = 'server1',
MASTER_PASSWORD = '12345',
MASTER_PORT = 3306,
MASTER_LOG_FILE = 'Type_your_log_file_name',
MASTER_LOG_POS = TYPE_YOUR_LOG_POSITION_HERE,
MASTER_CONNECT_RETRY = 10,

START SLAVE;

SHOW SLAVE STATUS \G;
-1
source

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


All Articles