Now I have a requirement that there are two projects, one called Project A, one project B, because the user table of A and B's user table are to be implemented the same.
For example: I registered in the A project, to be able to login in Project B
Since the data used is MySQL, you can use the federated engine to achieve this requirement.
Environment
First of all, find out if MySQL has federated this engine. I have mysql5.7.22.
Show engines;
Results
Mysql> Show engines;+--------------------+---------+--------------------------------------------------------- -------+--------------+------+------------+| Engine | Support | Comment | Transactions | XA | savepoints |+--------------------+---------+----------------------------------------------------------------+--- -----------+------+------------+| InnoDB | DEFAULT | Supports transactions, Row-level locking, and foreign keys | YES | YES | YES | | CSV | YES | CSV Storage Engine | NO | NO | NO | | MyISAM | YES | MyISAM Storage Engine | NO | NO | NO | | Blackhole | YES | /dev/null Storage Engine (anything you write to it disappears) | NO | NO | NO | | Performance_schema | YES | Performance Schema | NO | NO | NO | | Mrg_myisam | YES | Collection of identical MyISAM tables | NO | NO | NO | | ARCHIVE | YES | Archive Storage Engine | NO | NO | NO | | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO | | Federated | NO | Federated MySQL Storage Engine | NULL | NULL | NULL |+--------------------+---------+----------------------------------------------------------------+--------- -----+------+------------+9 rows in Set (0.00 sec)
This is there, in the last item, but it does not open, then the next is much more convenient.
The first step
Add federated to my.cnf to open this property.
Check again.
The following is the addition of federated in the build table statement.
Step Two
Claims engine connection Properties account password IP port database table engine =federated connection= ' Mysql://root:[email protected]:3306/zskdb/cas_user ' ;
Add the above engine when creating the table structure in slave.
CREATE TABLE ' cas_user ' ( ' id ' varchar (255) NOT NULL COMMENT ' id ', ' encryid ' varchar (255) DEFAULT NULL COMMENT ' encryption After the user ID ', ' name ' varchar (255) default null COMMENT ' user name ', ' password ' varchar (255) default null COMMENT ' password ', ' Mobile ' varchar (+) default null COMMENT ' mobile number ', ' email ' varchar (+) default null COMMENT ' mailbox ', ' sex ' int (1) DEF Ault NULL COMMENT ' sex (0: Male, 1: female) ', ' credit ' double (11,2) DEFAULT ' 0.00 ', PRIMARY key (' oid '), UNIQUE KEY ' Upk_ USER_ID ' (' id ')) engine=innodb auto_increment=9 DEFAULT charset=utf8 comment= ' user table ' ENGINE =federated connection= ' MySQL ://root:[email Protected]:3306/zskdb/cas_user ';
As can be seen from the above, I have my own table has the InnoDB engine, I added another in the back.
Note: As long as the table structure is on the line, the data is automatically mapped from master.
Demo: As long as the Cas_user table in master has operations, the same action is shown in slave, I delete two data in master, open slave Cas_user will find that the data is also less than the deleted two.
MySQL Add federated engine problem