Performance of querying across two mysql databases on the same server?

前端 未结 2 407
长发绾君心
长发绾君心 2021-01-04 08:07

Is there any performance hit from querying over two (or more) databases on the same MySQL server, compared to if those databases had been merged into one?

Background

2条回答
  •  悲哀的现实
    2021-01-04 08:30

    This would only introduce a noticeable problem if you were trying to use multiple select statements for the data in each database. It would be better to use some foreign keys, and then use a single join query to get a user's data and his associated user content. You can prefix schema names on your tables in the select join statement.

    example would be similar to this:

    SELECT a.user, b.user_content
        FROM database1.table1 AS a
        LEFT JOIN database2.table2 AS b
            ON a.user = b.user_id;
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题