Deepak Kapoor
Deepak Kapoor

Reputation: 13

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). 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.

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.

How can I connect my local host instance with shopify_data instance and get data within the same query.

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

Upvotes: 1

Views: 6577

Answers (2)

Rai Singh
Rai Singh

Reputation: 69

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.
  2. Create a mysql user "anydbuser" which can access all database of your server. In plesk this option come when user created from database selection dropdown choose ANY.
  3. now connect testdb using anydbuser.
  4. In query window you can try this query : select * from original_db_name.tablename;
  5. you are able to access result of above db table into testdb query window

Upvotes: 0

Mike Lischke
Mike Lischke

Reputation: 53337

It's not possible to access data stored on different servers in a single connection, with 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).

Upvotes: 1

Related Questions