MySQL - Does Federated Engine have to be enabled on both servers? - mysql

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';

Related

It is possible to select table from database of remote server2 even you are in the remote server1, Not in local server?

I have Remote_Server1 and Remote_Server2. From Remote_Server1 i want to select tables in the database of Remote_Server2
It is possible? If yes, How?
I try to use federated engine but it only in local server. I did not use local i want to use the remote server in my program.
If the solution is to enable federated engine in Remote server, How can I enabled it in my desktop?
I am new at Mysql.

Is there a way to create a linked "database" in mariadb?

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

Linking MySql Database to Azure

I have a Database using MySql, however i want to migrate to azure MySql which i know is possible, I am new to Azure.
My question if i make changes to the local database, is it possible to automatically update the tables in azure with same changes?
I want to link both Database together and any changes effected on any will affect the other.
This functionality is available and is called Data-In replication. Please see: How to configure Azure Database for MySQL Data-in Replication for instructions on how to configure this functionality. Please see the Limitations and Considerations but the following are the requirements:
The master server version must be at least MySQL version 5.6.
The master and replica server versions must be the same. For example, both must be MySQL version 5.6 or both must be MySQL version 5.7.
Each table must have a primary key.
Master server should use the MySQL InnoDB engine.
User must have permissions to configure binary logging and create new users on the master server.
If the master server has SSL enabled, ensure the SSL CA certificate provided for the domain has been included in the mysql.az_replication_change_master stored procedure. Refer to the following examples and the master_ssl_ca parameter.
Ensure the master server's IP address has been added to the Azure Database for MySQL replica server's firewall rules. Update firewall rules using the Azure portal or Azure CLI.
Ensure the machine hosting the master server allows both inbound and outbound traffic on port 3306.
Ensure the master server has a public IP address, the DNS is publicly accessible, or has a fully qualified domain name (FQDN).

Create view in MySQL ndbcluster engine

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.

MySQL Federated table crashes MySQL workbench

I just enabled Federated engine on MySQL 5.5 server. I set up a federated table on another server and made sure I had an IP passthrough setup on the server I'm connecting to on MySQL port. The connection is really slow. In MySQL workbench, initially selecting the table or especially right clicking on the table causes MySQL workbench to lock up and I have to force it to close. If it does finally let me click on it, I get an error when trying to query data:
Error Code: 1429. Unable to connect to foreign data source: Can't connect to MySQL server on 'server IP' (110)
I have another MySQL server where I set up the same Federated table to the same destination server and I have no problems querying data.
I just found out the issue. It was due to MySQL not having the proper permissions. I started getting an "Error Code: 1159 Got timeout reading communication packets" message. Turned out the view I was pulling into the federated table was so huge, that it was causing timeouts. Dumping the view into a cache table and setting it up with a proper index and linking the Federated Table to the cache table solved the problem.