DBA

DBA

DBA May 31, 2017


Database Administration Notes

Database replication and synchronization

Resources:

Mysql database sync between two databases

Sync two MySQL databases in two different locations

Replication

Database Synchronization

Binary Log

How to sync a MySQL table between two remote databases.

<?php
$tableName = 'some_table';
$sql =
   "SELECT * 
    FROM $tableName";
$pathToCsv = '/tmp/some-file.csv';
$command = sprintf("mysql -h %s -u %s  --password=%s -D %s -e '%s' > %s",
    '10.0.0.2', 
    'db-user', 
    'db-password', 
    'database_name', 
    $sql, 
    $pathToCsv);
exec($command);

$sql =
   "LOAD DATA LOCAL INFILE '$pathToCsv'
    REPLACE INTO TABLE `$tableName`
    CHARACTER SET 'utf8'
    IGNORE 1 LINES";
$db->execute($sql); // Using your favourite database adapter
PlaceholderThumbnail