What you want is the resource of Federated tables
mysql.
This feature is available from Mysql 5.
With it it is possible to interconnect two different Mysql databases as follows:
Create the remote table
CREATE TABLE test_table (
id INT(20) NOT NULL AUTO_INCREMENT,
name VARCHAR(32) NOT NULL DEFAULT '',
other INT(20) NOT NULL DEFAULT '0',
PRIMARY KEY (id),
INDEX name (name),
INDEX other_key (other)
)
ENGINE=MyISAM
And at the local bank, recreate the same table structure, changing the Engine
for Federated
and inserting the remote bank path into Connection
CREATE TABLE federated_table (
id INT(20) NOT NULL AUTO_INCREMENT,
name VARCHAR(32) NOT NULL DEFAULT '',
other INT(20) NOT NULL DEFAULT '0',
PRIMARY KEY (id),
INDEX name (name),
INDEX other_key (other)
)
ENGINE=FEDERATED
CONNECTION='mysql://fed_user@remote_host:9306/federated/test_table';
As an alternative to the connection string of Connection
, it is possible to create a nickname for that server via the command CREATE SERVER
:
CREATE SERVER remote
FOREIGN DATA WRAPPER mysql
OPTIONS (USER 'Remote', HOST '192.168.1.106', DATABASE 'test');
CREATE TABLE federated_table (
id INT(20) NOT NULL AUTO_INCREMENT,
name VARCHAR(32) NOT NULL DEFAULT '',
other INT(20) NOT NULL DEFAULT '0',
PRIMARY KEY (id),
INDEX name (name),
INDEX other_key (other)
)
ENGINE=FEDERATED
CONNECTION='remote';
References
How to Use FEDERATED Tables
CREATE SERVER Syntax
In case this table will be as FEDERATED it will only make use of the table it mirrors online? Or I can handle it both locally and on the web that it carries itself as I work on and in the other.
– DevAgil
Good question, I do not know what the behavior of these tables when there is no connection to the remote base
– gmsantos
Best situation would be to make a test in these functions. Thank you very much.
– DevAgil
@Claytonquintiliano follows a case of how to configure a Federated with failover http://www.onlamp.com/pub/a/onlamp/2006/04/20/advanced-mysql-replication.html?page=4
– gmsantos
Thanks @gmsantos.
– DevAgil