I need to join table from other database and sometimes other server

后端 未结 4 1283
你的背包
你的背包 2020-12-16 06:42

My project has its own database. Also, I use table of users, which is on other database. Two offices have their data on the same server, but third one has its own user table

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 06:49

    Federated tables are your solution for tables on other servers. They are very slow though if you perform joins on them. If you just want to read data from another database on the same server you can use a view. This way you have all tables virtually in one database and you have to open only one connection in your application.

    CREATE
        VIEW `my_db`.`table_name` 
        AS
    (SELECT * FROM `other_db`.`table_name`);
    

提交回复
热议问题