如何在MySQL中构造跨数据库查询? [英] How do I construct a cross database query in MySQL?

查看:115
本文介绍了如何在MySQL中构造跨数据库查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一服务器上有两个数据库. Google给了我一些提示,但是我找不到任何官方"信息.有人可以指出我的文档来说明如何执行此操作吗?使用PHP的说明也将很有用.谢谢!

I've got two databases on the same server. The Google gave me some hints but there wasn't anything "official" that I could find. Could someone point me to the documentation that explains how to do this? An explanation using PHP would be useful as well. Thanks!

推荐答案

我在同一台服务器上有两个数据库. ...如何在MySQL中构建跨数据库查询?

I've got two databases on the same server. ...How do I construct a cross database query in MySQL?

通过在表的前面加上适当的数据库名称,可以访问同一MySQL实例上的其他数据库. IE浏览器:

You access other databases on the same MySQL instance by prefixing the table with the appropriate database name. IE:

SELECT *
  FROM this_database.table_1 t1
  JOIN that_database.table_2 t2 ON t2.column = t1.column

记住

查询将使用用于设置身份验证的身份验证凭据来执行 联系.如果要跨两个(或多个)同时查询两个表 数据库,用于运行查询的用户将需要对所有 涉及的数据库.

Keep in mind

A query executes with the credentials of the authentication used to set up the connection. If you want to query two tables simultaneously across two (or more) databases, the user used to run the query will need SELECT access to all databases involved.

这篇关于如何在MySQL中构造跨数据库查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆