之前我介绍过mysql的federated引擎,他可以解决mysql跨服务器的查询问题,但是他同时有个致命的弊端:
ImportantWhen you create the local table it must have an identical field definition to the remote table.
federated必须本地映射的表与远端的表结构一致
摘自mysql官网:https://dev.mysql.com/doc/refman/5.7/en/federated-create.html
而在上一张我介绍了mysql的视图,他就是可以将一张表只显示你需要显示的字段,这样就相当于你将字段固定了,源表再怎么添加字段你都不会受影响了,操作如下:
create table t_table ( id int not null auto_increment primary key ) engine = innodb; create or replace view v_view as select * from t_table; create table f_fed_table ( id int not null ) ENGINE=FEDERATED CONNECTION='mysql://user:[email protected]:3306/test/v_view';