5

I am using PHP and Mysql for developing an application. we have two copies of database, one at local server(i.e our end) and one at web server. we want to sync both the database so that if any change made in local database should also reflect on the webserver database. is that possible?? Currently we are using PHP scripts to do so..which is taking too much of time and aswell as not reliable. What can be done so that MySQL will internally fire the whole update and logic??

NOTE:- Our Local server run's on Windows, and web server is Unix based, and we are not using command line to access both the machines, actually at both the sides we use PHP application to update and maintain data(i.e to add new or update data)

2
  • Please add details ... what platform / OS ... whether you have command line access to both machines .... Commented Oct 20, 2010 at 11:32
  • @Pekka is there any issue if we use PHP scripts than using MySQL replication?? Commented Oct 20, 2010 at 11:42

3 Answers 3

4

MySQL Replications might be what you are looking for, but i do not recommend to sync development and production databases. This can get you in trouble when continuing development after webpage has been released. The common approach is to have a server for development (dummy data, not public), testing (real data, not public) and production (real data, public).

Sign up to request clarification or add additional context in comments.

Comments

1

To Sync Local Database with Web Server Database in MySql you can achieve this functionality via using Replication. Here i have some SQL Commands to perform Replication

1). Here you need two PCs if you are doing it offline for testing purpose and first PC will be your MASTER and other will be act as SLAVE.

2). Check the IP address of your Machines.

3). I am performed it on Localhost with two these following PCs

Machine-1 :- 192.168.1.20

Machine-2 :- 192.168.1.21

and then open you Mysql and Start typing these commands on both machines as given below

---------------- 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;

2 Comments

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.
Thanks for suggestion @NarendraSisodia . Now check it out i updated the whole answer is it fine now??
0

edit: I thought the webserver one also was a master.

In this case, look at the way replication in MySQL works; it will simply copy data pushed to the local database to the webserver one.

1 Comment

i thought it was master-slave as local being master and webserver being slave.. actually for the first time i am working on a system like this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.