Search code examples
mysqlfederated

Federated - enable trouble


Lets say we have MySQL server A, where we need to create a 'copy' of table, which is situated on server B.

We don't have federated enabled. Reseting server A would cause much trouble and I believe, we cannot enable federated without reseting. I also believe that it is not enough to enable it on the B server (correct me if I'm wrong in anything)

What other solutions do we have? Is there something enabled by default in mysql server? Any ideas?


Solution

    • You need federated enabled just on server B
    • You can access a view on A by making a federated table on B
    • You can do INSERT UPDATE DELETE on federated table
    • If you need read-only access you can limit the user privileges

    BUT! You can't do any aggregate func. on a view which will be federated (ex. COUNT(), MAX(), UNION...) (you can, however it will lag)

    • Remember to set the KEY's on the federated table you are creating. (or it will lag horr.)
    • Remember to use ALGORITHM=MERGE on views
    • Remember to grant acces to USERNAME(from connection string) on server A

    example of a federated table on server B:

    delimiter $$
    CREATE TABLE `schemaName`.`tableName`(
        `keyName` VARCHAR(10) NOT NULL,
        `key2Name` DATE DEFAULT '2012-01-01',
        KEY `keyName` (`keyName`) 
    )
    ENGINE=FEDERATED
    DEFAULT CHARSET=utf8
    CONNECTION='mysql://USERNAME:PASSWORD@IPADDRESS:PORTNUMBER/baseSchema/baseTable'
    $$
    

    And the view on server A:

    CREATE
        ALGORITHM = MERGE
        DEFINER = `ANOTHERUSERNAME`@`%`
        SQL SECURITY DEFINER
    VIEW `baseSchema`.`baseTable` AS
        SELECT
            ... AS `keyName`,
            ... AS `key2Name`
        FROM
            ...