简体   繁体   English

mysql工作台连接多个数据库

[英]mysql workbench connect with multiple database

I have two different instances on my workbench localhost and remote server instance shopify_data, (default schema sales_report).我的工作台本地主机和远程服务器实例 shopify_data 上有两个不同的实例(默认架构 sales_report)。 Now I want to fetch the data from table zipcode in localhost and other fields that are in another table shopify_orders in remote server shopify_data within sales_report.现在,我想从 localhost 中的表邮政编码和 sales_report 中远程服务器 shopify_data 中另一个表 shopify_orders 中的其他字段中获取数据。

The query looks like :查询看起来像:

SELECT Name, billing_zip, Billing_Name, Billing_Address1,Billing_Address2, Lineitem_name, Created_at
  FROM sales_report.shopify_orders 
 WHERE Created_at between '2017-08-31' and '2017-09-21' and Billing_Zip in (select zip_code from zipcode);

It gives error:它给出了错误:

sales_report.shopify_orders does not exists. sales_report.shopify_orders 不存在。

How can I connect my local host instance with shopify_data instance and get data within the same query.如何将本地主机实例与 shopify_data 实例连接并在同一查询中获取数据。

Thanks.谢谢。

Deepak迪帕克

PS: I don't want to import the shopify_orders into local host as the value keeps dynamically changing with each order and I don't want to repeat importing PS:我不想将 shopify_orders 导入本地主机,因为值随着每个订单而动态变化,我不想重复导入

It's not possible to access data stored on different servers in a single connection, with MySQL. 使用MySQL不可能在单个连接中访问存储在不同服务器上的数据。 You always open a connection to a single server and can work with DB objects available on that (provided you have the privileges for that). 您总是打开与单个服务器的连接,并且可以使用该服务器上的可用数据库对象(前提是您具有该服务器的特权)。

I should add there's the option of federated tables . 我应该添加联邦表的选项。 More precisly it's a storage engine, which allows to host data on a remote server in a local table, which then makes it possible to do joins with both local and remote data. 更确切地说,它是一个存储引擎,它允许将数据托管在本地表中的远程服务器上,然后可以对本地和远程数据进行联接。 But that requires to define such tables first and you cannot use FKs (and there are other limitations). 但这需要首先定义此类表,并且您不能使用FK(并且还有其他限制)。

In workbench you can work with multiple databases on same server in crossing manner mean to say in query window of one database you can access other database tables also.在工作台中,您可以以交叉方式使用同一服务器上的多个数据库,这意味着在一个数据库的查询窗口中您也可以访问其他数据库表。 For this follow the following steps:为此,请执行以下步骤:

  1. The database on which you are working on localhost create this as testdb on your remote server.您在 localhost 上工作的数据库将其创建为远程服务器上的 testdb。
  2. Create a mysql user "anydbuser" which can access all database of your server.创建一个可以访问您服务器的所有数据库的 mysql 用户“anydbuser”。 In plesk this option come when user created from database selection dropdown choose ANY.在 plesk 中,当用户从数据库选择下拉列表中创建时,此选项会出现,选择 ANY。
  3. now connect testdb using anydbuser.现在使用 anydbuser 连接 testdb。
  4. In query window you can try this query : select * from original_db_name.tablename;在查询窗口中,您可以尝试以下查询: select * from original_db_name.tablename;
  5. you are able to access result of above db table into testdb query window您可以将上述 db 表的结果访问到 testdb 查询窗口中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM