Is there any way to use the join operation for two tables from different databases?
Both databases are on different server.
If both databases are MySQL, then FEDERATED ENGINE provides functionality to join MySQL databases in different servers.
And read the limitations too.
Wikipedia:
The MySQL Federated storage engine for the MySQL relational database management system is a storage engine which allows a user to create a table that is a local representation of a foreign (remote) table. It utilizes the MySQL client library API as a data transport, treating the remote data source the same way other storage engines treat local data sources whether they be MYD files (MyISAM), memory (Cluster, Heap), or tablespace (InnoDB). Each Federated table that is defined there is one .frm (data definition file containing information such as the URL of the data source). The actual data can exist on a local or remote MySQL instance.
To create a Federated table, one has to specify a URL in the "CONNECTION" string:
create table t1 (
a int,
b varchar(32))
ENGINE=FEDERATED CONNECTION='mysql://user#hostname/test/t1'
The connection URL is in the format of:
scheme://user:pass#host:port/schema/tablename
Related
The title pretty much says it all.
I was wondering how changes to the remote or local table (e.g. adding a column) would affect the connection between them and could not find any resources about it.
So does this work? (I assume it does not, because otherwise there would not be the constraint that both must have the same schema in the first place) But if it works, is it bi-directional and what steps have to be done?
I would appreciate any help and especially links to resources about this problem.
If you alter the base table on the remote system, you would have to DROP and then re-CREATE the federated table that connects to it.
https://dev.mysql.com/doc/refman/8.0/en/federated-usagenotes.html says:
The FEDERATED storage engine supports SELECT, INSERT, UPDATE, DELETE, TRUNCATE TABLE, and indexes. It does not support ALTER TABLE...
There is no way for the FEDERATED engine to know if the remote table has changed.
https://dev.mysql.com/doc/refman/8.0/en/federated-create.html says:
When you create the local table it must have an identical field definition to the remote table.
So maintaining a federated table is a somewhat manual process, and it's not supported to have continuous access to it if you ALTER TABLE on the remote end.
Frankly, I've never found a good use for federated tables. I'd rather code my application to connect to multiple database instances and query the tables directly.
Edit: the answer to the first question is that the application calls the reader instance of the cluster. I can reproduce the problem with workbench if I execute the procedure on the reader instance.
I have a stored procedure with a temporary table. I am using Amazon AWS RDS (Aurora) MySql. I create the temporary table like:
create temporary table if not exists tmpResources(
pkKey varchar(50) NOT NULL, PRIMARY KEY(resource), UNIQUE KEY(resource),
...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
When I call the procedure from MySql workbench it executes fine. When I call it from my application, I receive the following error:
The 'InnoDB' feature is disabled; you need MySQL built with 'InnoDB'
to have it working
I have an asp.net web application, using the Oracle c# drivers version 8.0.20. AWS RDS is currently MySql version 5.7.12.
There are 2 very perplexing questions:
1. Why does it work differently when called from workbench? The error seems to be coming from server side.
2. Why do I get this error about InnoDB disabled, when it is clearly not disabled?
Thanks for any insight...
Edit: I verified this with AWS technical support - temp tables on reader clusters are MyISAM. My initial problem involves indices on MyISAM databases, but I will post that as its own question. The response from AWS RDS/Aurora team follows:
this is by design in Aurora, and it is because when a temporary table or a system generated internal temp table is created on writer with InnoDB, it needs to go to underlying storage for readers in the cluster, but when you create temporary table on the reader, it is just for that particular reader instance and does not populate to other nodes, hence by default reader instances will pick up MyISAM engine. This behavior is attributed to the fact that the value of the variable “innodb_read_only” is set as ON for readers and OFF for writers, thus restricting the creation of InnoDB tables on the reader instances
Initial response:
It appears the issue is with readers. Temporary tables on stored procedures in the reader RDS instances are not InnoDB, even though this is not documented anywhere and the instance type/price is the same for readers as for the writer. What they are exactly I don't know, I have a question to AWS about it. If they respond I'll post here.
We want to have schemas/database for each functionality on our MySQL Server; so that if load on DB grows; we can move that particular schema to independent server anyday.
How to restrict Joins across Schemas in MySQL ?
I guess we can do database1.table1 join database2.table2 on etc. I.e. join tables in separate databases on the same server.
Is it possible to join tables across different sql servers?
you can use FEDERATED Storage Engine.
The FEDERATED storage engine lets you access data from a remote
MySQL database without using replication or cluster technology.
Querying a local FEDERATED table automatically pulls the data
from the remote (federated) tables. No data is stored on the local tables.
The site shows a good illustration
Environment: JSF2, persistence with Hibernate, MySQL
I have a database that is rappidly filling because of a table with image data. That data is never searched but only directly accessed by id. Problem is that it stays in the database and so enlarges the backups and the runtime memory usage of the database.
I'm thinking that there could possibly be multiple solutions:
Tell MySQL that the table should not be cached and/or kept in memory.
Don't use MySQL at all for that table. Just let persistence know that this should be stored on disk directly.
???
But I haven't found a way to do either. Please advice.
Thanks,
Milo van der Zee
Storage type depends on storage engine in MySQL. Only tables having MEMORY storage engine are stored in RAM others are stored on disk.
In select queries you can use SELECT SQL_NO_CACHE to tell MySQL not to cache query data in MySQL query cache.
You can partition the table by defining partitions on table. This will make inserts and selects faster.
You can also create day wise tables like table_name_2012_07_20 and archive tables with old dates and to store data in compress format you can either use Archive storage engine or if you are using MyIsam storage engine then do myisamchk or myisampack to save disk space on the hard drive.