How to connect two mysql databases on two different machines?

I have a mysql database named "sample1" on one of my windows laptops and another mysql database named "sample2" on another machine. First, I want to link both of these machines and link the sample database “sample1” and “sample2” so that the query that I executed in “sample1” should also appear in “sample2” (distributed query processing).

For example: if sample1 and sample2 contain 5 records, then deleting the record in sample1 should also be reflected in sample2.

I use WAMP and work on PHP with MySQL. Please help ...

+4
source share
4

, , sample1 sample2 .

, ( , ) - mysql: https://dev.mysql.com/doc/refman/5.0/en/replication-howto.html

EDIT: , , , ( ) , , .

+1

MySQL ($ conn1 $conn2), .

$database1 = "students";
$database2 = "employees";
$conn1 = mysql_connect('host1', 'user', 'password');
if(!$conn1) {
    die("Not connected: ". mysql_error());
}else{
    mysql_select_db($database1, $conn1);
}

$conn2 = mysql_connect('host2', 'user', 'password', TRUE);
if(!$conn2) {
    die("Not connected: ". mysql_error());
}else{
    mysql_select_db($database2, $conn2);
}
+1

2 .

, !

0

, .

, Falko Timme, , exampledb IP- 192.168.0.100 . ( ) Debian Sarge; .

, /etc/mysql/my.cnf. MySQL, MySQL IP-, ( ):

#skip-networking
#bind-address            = 127.0.0.1

, MySQL, ( , , ), , , MySQL . exampledb, /etc/mysql/my.cnf:

log-bin = /var/log/mysql/mysql-bin.log
binlog-do-db=exampledb
server-id=1

MySQL:

/etc/init.d/mysql restart

MySQL root :

mysql -u root -p
Enter password:

MySQL.

GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY '<some_password>'; (Replace <some_password> with a real password!)
FLUSH PRIVILEGES;

( MySQL) :

USE exampledb;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;

- :

+---------------+----------+--------------+------------------+
| File          | Position | Binlog_do_db | Binlog_ignore_db |
+---------------+----------+--------------+------------------+
| mysql-bin.006 | 183      | exampledb    |                  |
+---------------+----------+--------------+------------------+
1 row in set (0.00 sec)

, !

MySQL:

quit;

exampledb . - , - LOAD DATA FROM MASTER; . , , , , , , . , , .

, :

mysqldump -u root -p<password> --opt exampledb > exampledb.sql (Replace <password> with the real password for the MySQL user root! Important: There is no space between -p and <password>!)

SQL- exampledb exampledb.sql. !

LOAD DATA FROM MASTER; .

Finally, we need to unlock the tables in exampledb:

mysql -u root -p
Enter password:
UNLOCK TABLES;
quit;
-1
source

All Articles