How to create distributed/mirrored dynamic scripting website (Step – 2 Database synchronization)

Step two: Database Syncrhonization
This is the key of the dynamic website synchronization, I will use mysql server 5.x for example, if you are using a different database server, you will need to find out how to configure their replication.

1. Configure Master & Slave Server
Create a mysql user for replication

Edit my.cnf file [mysqld] section

2. Copy the database:
We need to lock table on master server before we dump the database

Write down the bin log file record & the postion & leave this connection open, then create a new ssh connection to the master server & dump the databse with:

Copy all_database.sql.gz to slave server & extract the files & import into slave database

An alternative way is to copy the content of folder /var/lib/mysql/data/* from master to slave.

Now you received exactly the same database on the salve server, then run SQL command on slave server

If you see Thread IO & Thread SQL are both running, then your database should be synchronized
Now go back to master server mysql session & run

Next: How to create distributed/mirrored dynamic scripting website (Step – 3 Security)