I was doing this process in a same server but different databases.
Insert data into a table in dev database
Check the data
If the data is fine, insert into a same table in prd database
but now I separated those databases into different servers. development server, production server.
I didn't want to edit so many existing queries, so I created federated tables that connected to the production server. but every time when I alter production tables.. I had to recreate federated tables again.
Is there a way to not recreate federated tables every time when I alter the original table?
Can I make a linked database?
This answer is assuming you have federatedX plugin available instead or in addition to federated.
You should try the following :
uninstall soname 'ha_federated.so' ;
install soname 'ha_federatedx.so' ;
If this is the case, the engine federatedx (used only for the plugin name, the engine name in DDL statements is still federated) you can use the following statements :
You create a server, as follow :
create server 'server_one' foreign data wrapper 'mysql' options
(HOST '192.168.1.123',
DATABASE 'first_db',
USER 'patg',
PASSWORD '',
PORT 3306,
SOCKET '',
OWNER 'root');
of course, you have to replace the values using your remote server ip, user, password, database, etc.
Later on, if anything change in your remote server properties, you just have to alter the server (no alter table are required anymore).
Then you create your local table using federated engine and the server you've created, as follow :
create table test_fed engine = federated connection = 'server_one' ;
Creating your local table like this will activate federatedx discovery mode, making your local table structure as the exact copy of the remote one.
What if your remote table structure change : unfortunately it's not automatic (the federatedx discovery mode is activated one time when the local table is created and it's not kept up to date), however, it's quiet easy as you just have to re-create your local table the same way
create or replace table test_fed engine = federated connection = 'server_one' ;
And you're done !
The drawback of this local tables declaration method, is to require your local tables' names to be exactly the same as remote ones
If you absolutely need different names for your local and remote tables, you can use the "old" connection syntax used in the create table (finishing with <remote_db_name>/<remote_table_name>)
Related
I'm moving from MySql to MariaDB and I have several databases using federated tables. Everything works fine in the MariaDB but when the server restarts, all federated tables stop working as if the remote server's entry doesn't exists on the local MariaDB server.
After every restart the servers' entries remain in the servers table in the mysql db. If I try to add them again with the CREATE SERVER command, I get an error as if they exist. If I try to drop them with DROP SERVER, I get an error as if they don't exist.
The only way to make it work again is to manually remove the entries from the server table with DELETE FROM servers and create them again with the command CREATE SERVER. How can I make those configurations persistent?
I've searched extensible and couldn't find any solution or mention about this issue. The tables work fine in MySql. The logs doesn't mention anything related to the FederatedX engine between restarts. I'm using MariaDB 10.3.18 on CentOS 7.
I just found that this issue only occurs if the servers table is using the InnoDB engine. Changing it to MyISAM or Aria solves the problem.
For some reason my server was installed with the wrong engine for this table.
Edit: bug report here.
I have installed and configured MySQL(ndbcluster engine) in two machines. Such as ip of those machines are xxx.xxx.xxx.1 and xxx.xxx.xxx.2.
I have created a db and some tables. I have created the tables only in one machine(xxx.xxx.xxx.1) with mentioning engine as ndbcluster. So I can see the tables in both machine(also in xxx.xxx.xxx.2).
But while I create a view in one machine. It doesn't show in the other machine!
What should I do to see the view in both machine by creating once in one machine.
Isn't it possible?
Or, do I need to create the view in both machine?
Another question: Can I create a view in mysql specifying the db engine(i.e: innodb, ndbcluster)?
N.B: My MySQL is server is configured as ndbcluster.
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
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).
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:
The database on which you are working on localhost create this as testdb on your remote server.
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.
now connect testdb using anydbuser.
In query window you can try this query : select * from original_db_name.tablename;
you are able to access result of above db table into testdb query window
I am attempting to run a single MySQL query, joining two databases on two servers.
I am aware of the potential poor performance, but would like to test regardless.
The purpose of this test, I am working on a Windows domain, with a development (local) server and a live (remote) server.
The local server has FEDERATED engine enabled and the remote server, which stores the actual data but FEDERATED engine is disabled.
Both tables (live and federated) have the same definition/schema, and the federated table on the local server has been defined:
ENGINE=FEDERATED
DEFAULT CHARSET=utf8
CONNECTION='mysql://remote_user#remote_server/remote_database/remote_table';
The local server table creates fine, and although the remote_user and remote_user#'MY-PC-NAME' has the correct GRANTS, I am getting an error:
ERROR 1429 (HY000): Unable to connect to foreign data source: Access denied for user 'remote_user'#'MY-PC-NAME' (using password
My question is do both the local and remote servers require the FEDERATED engine to be enabled?
If not, is there anything else I need to do to get the federated table
to work?
FEDERATED engine option is not required to be enabled on both servers, in this case, only the local server where the federated table is stored, requires to be enabled.
It turns out that the remote_user user requires the PASSWORD option.
I used this to get the connection to work:
CONNECTION='mysql://remote_user:password#remote_server/remote_database/remote_table';
I confused by posts ,
that Federated engine copies a table from Remote database to local
database
(or)
Federated engine creates virtual table in local database from remote
database
.
can some one support what it actually does.?
Federated engine creates virtual table in local database from remote database ,
To copy entire table from remote database use replication , follow http://dev.mysql.com/doc/refman/5.1/en/replication-howto.html