2
I have the table below in 2 servers and I need server 1 to send all this information to server 2 ie fields id, username, iddns, dns, ipdnstipo e ipdns
as it is.
Table
CREATE TABLE IF NOT EXISTS `trad` (
`id` int(11) NOT NULL,
`username` varchar(50) NOT NULL,
`iddns` int(11) NOT NULL,
`dns` varchar(255) DEFAULT NULL,
`ipdnstipo` varchar(10) DEFAULT NULL,
`ipdns` varchar(64) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `trad` (`id`, `username`, `iddns`, `dns`, `ipdnstipo`, `ipdns`) VALUES
(1, 'master', 0, 'exemplo.com.', 'A', '10.0.0.101'),
(1, 'master', 1, 'dns1.exemplo.com.', 'A', '10.0.0.101'),
(1, 'master', 2, 'dns2.exemplo.com.', 'A', '10.0.0.102'),
(1, 'master', 3, 'dns3.exemplo.com.', 'A', '10.0.0.103'),
(1, 'master', 4, 'dns4.exemplo.com.', 'A', '10.0.0.101'),
(1, 'master', 5, 'dns5.exemplo.com.', 'A', '10.0.0.102'),
(1, 'master', 6, 'dns6.exemplo.com.', 'A', '10.0.0.103'),
(1, 'master', 7, 'dns7.exemplo.com.', 'A', '10.0.0.101'),
(1, 'master', 8, 'dns8.exemplo.com.', 'A', '10.0.0.102'),
(1, 'master', 9, 'dns9.exemplo.com.', 'A', '10.0.0.103'),
(1, 'master', 100, 'exemplo1.com.', 'A', '10.0.0.101'),
(1, 'master', 1000, 'exemplo1.com.', 'A', '10.0.0.102'),
(1, 'master', 10000, 'exemplo1.com.', 'A', '10.0.0.103'),
(1, 'master', 101, 'dns1.exemplo1.com.', 'A', '10.0.0.101'),
(1, 'master', 102, 'dns2.exemplo1.com.', 'A', '10.0.0.102'),
(1, 'master', 103, 'dns3.exemplo1.com.', 'A', '10.0.0.103'),
(1, 'master', 200, 'exemplo2.com.', 'A', '10.0.0.101'),
(1, 'master', 2000, 'exemplo2.com.', 'A', '10.0.0.102'),
(1, 'master', 20000, 'exemplo2.com.', 'A', '10.0.0.103'),
(1, 'master', 201, 'dns1.exemplo2.com.', 'A', '10.0.0.101'),
(1, 'master', 202, 'dns2.exemplo2.com.', 'A', '10.0.0.102'),
(1, 'master', 203, 'dns3.exemplo2.com.', 'A', '10.0.0.103');
I only got this from my research but it doesn’t work.
<?PHP
$db_host1 = "10.0.0.101";
$db_user1 = "dns";
$db_password1 = "123456";
$db_name1 = "dns";
$db_connect1 = mysqli_connect($db_host1, $db_user1, $db_password1, $db_name1);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$db_host2 = "10.0.0.102";
$db_user2 = "dns";
$db_password2 = "123456";
$db_name2 = "dns";
$db_connect2 = mysqli_connect($db_host2, $db_user2, $db_password2, $db_name2);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query(
$db_connect1,
"SELECT * FROM trad"
);
$rows = mysqli_fetch_array($result,MYSQLI_NUM);
foreach ($rows as $row) {
$trad = $row;
mysqli_query(
$db_connect2,
"REPLACE INTO trad"
);
}
mysqli_close($db_connect1);
mysqli_close($db_connect2);
?>
this second server has the backup function only ?
– Otto
Hello good night Not to backup because some parts will be changed by another php on the second server
– Ricardo Jorge Pardal
I think the best way out here would be a replication system, the following article has an interesting example https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-in-mysql
– Renato Tavares
Thank you very much but already knew the tutorial and not quite that I only want to do the full update of 2 or 3 tables and increase the field in server 2 when inserted in server 1 if possible
– Ricardo Jorge Pardal
I think we can improve on this title... It’s too long and confused, I think the previous one was clearer. The statement is the ideal place to put the details, not the title.
– Bacco
You have released server 1 IP on server 2 as authorized host to access?
– Jader A. Wagner
Yes the field of connections from one server to another are working smoothly they are included with an include_once and are already serving other files.
– Ricardo Jorge Pardal
I’m afraid mysql does not have a Linked server style feature. Maybe the way is to implement in the application.
– Thiago Custodio
I managed to solve one of my problems which was a specific field from one server to another as you can see here links now I need the whole table
– Ricardo Jorge Pardal