I need to create a view in a MySQL database that displays data from another MySQL database on another server. Ideally, I also want the view to include some data from the local MySQL database (using JOIN to include some data from one of the local tables).
Can I create a VIEW that queries multiple databases if one of those databases is on a remote server? I'm hung up on how to handle the connection string to the remote database, yet still preserving the credentials needed for the localhost.
Well first off you are going to have to create a Linked Server in your MySQL DB Server. Then when you run your queries, you would reference that linked server like this: (can't remember exactly off hand, google should find it quick enough)
Megunticook
Member
1 Points
14 Posts
create a MySQL view that queries a remote db server
Jan 22, 2013 01:08 PM|LINK
I need to create a view in a MySQL database that displays data from another MySQL database on another server. Ideally, I also want the view to include some data from the local MySQL database (using JOIN to include some data from one of the local tables).
Can I create a VIEW that queries multiple databases if one of those databases is on a remote server? I'm hung up on how to handle the connection string to the remote database, yet still preserving the credentials needed for the localhost.
Any ideas? Thanks.
bbcompent1
All-Star
32974 Points
8505 Posts
Moderator
Re: create a MySQL view that queries a remote db server
Jan 22, 2013 01:57 PM|LINK
Well first off you are going to have to create a Linked Server in your MySQL DB Server. Then when you run your queries, you would reference that linked server like this: (can't remember exactly off hand, google should find it quick enough)
remotedbname..database.table
bbcompent1
All-Star
32974 Points
8505 Posts
Moderator
Re: create a MySQL view that queries a remote db server
Jan 22, 2013 01:59 PM|LINK
Its called Federated Tables: http://stackoverflow.com/questions/178401/can-mysql-5-0-have-a-view-of-a-table-located-on-another-server
Megunticook
Member
1 Points
14 Posts
Re: create a MySQL view that queries a remote db server
Jan 24, 2013 12:18 AM|LINK
Thanks. As it turns out, both databases are on the same server.
Can I simply prepend the name of the database? So to create the view it would look like this perhaps:
bbcompent1
All-Star
32974 Points
8505 Posts
Moderator
Re: create a MySQL view that queries a remote db server
Jan 29, 2013 12:24 PM|LINK
Even though it is still on the same server it will still require federated tables: http://stackoverflow.com/questions/508100/mysql-select-from-another-server