mysql中表与另一台机器的表同步更新


CREATE TABLE `user_data` (
  `FD_OBJECTID` varchar(30) default NULL,
  `id` bigint(20) NOT NULL auto_increment,
  `name` varchar(64) default NULL,
  `record_id` decimal(22,0) default '0',
  PRIMARY KEY  (`id`),
  KEY `IND_MAIN` (`id`)
) ENGINE=FEDERATED DEFAULT CHARSET=utf8 CONNECTION='mysql://admin:[email protected]:3306/dataname/user_data';

mysql是通过Federated引擎实现很多跨服务器访问的情况.

  要配置Federated引擎,需要mysql5.0以上的版本,具体配置方法如下:

  1.查看是否安装了federated引擎

   输入命令:show engines;

   结果如下:

    Engine Support Comment Transactions XA Savepoints
    MEMORY YES Hash based, stored in memory, useful for temporary tables NO NO NO
    FEDERATED NO Federated MySQL storage engine   
    MyISAM YES Default engine as of MySQL 3.23 with great performance NO NO NO
    BLACKHOLE YES /dev/null storage engine (anything you write to it disappears) NO NO NO
    MRG_MYISAM YES Collection of identical MyISAM tables NO NO NO
    CSV YES CSV storage engine NO NO NO
    ARCHIVE YES Archive storage engine NO NO NO
    InnoDB DEFAULT Supports transactions, row-level locking, and foreign keys YES YES YES

    从中可以看出federated引擎没有开启.

  2.开启federated引擎

   windows下在my.ini中加入federated,即可开启;

   linux中,需要编译时加入选项,再在my.ini中加入federated,方可开启.

3.建立远程数据表链接  

  假如:在ServerA上有一个数据库dbtestA,在ServerB上有数据库dbtestB,要在ServerB的数据库dbtestB上建立 ServerA的数据库dbtestA上的表tabletestA的数据表链接remote_tabletestA,语句如下:

create table remote_tabletestA ... ... engine=federated connection = 'mysql://root:123123@ServerA:3306/dbtestA/tabletestA';

4.使用远程数据表链接

  如上例,直接在ServerB的数据库dbtestB上对表remote_tabletestA进行操作,即是操作ServerA上数据库dbtestA的表tabletestA.

猜你喜欢

转载自tmuffamd.iteye.com/blog/2258812