:::: MENU ::::
Posts tagged with: remote mysql

Installing MySQL Engine(s) Post-Install

Background – My Need For Federated

I was working on a proof-of-concept the other day and ran into a situation. I separated my databases based off it’s perceived functionality. Example, Billing vs Content. The front-end application will only talk to the Content database, while the Billing database is accessed via the backend. This is a perfect concept except for the fact that my Users table was linked to the Billing database but not the Content database. That is an easy fix.

MySQL supports an engine called Federated. The purpose of Federated is to allow access to a remote database/table without the need to synchronization or replication. All you have to worry about is making sure your table descriptions are the same.

Find your plugin shared libraries. I know that federated was needed and searched on that:

splug@vanilla:~/mysql-5.5.15$ sudo find / -name "*federated.so"
/usr/local/mysql-5.5.15/lib/plugin/ha_federated.so
/home/splug/mysql-5.5.15/storage/federated/ha_federated.so

Now it’s time to install it:

//Example:
// mysql> install plugin <name> soname '<filename>.so';
mysql> install plugin federated soname 'ha_federated.so';

If you see the engine listed, but support is set to ‘NO’, you are missing the configuration options in my.cnf.

mysql> show engines;
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                    | Transactions | XA   | Savepoints |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| FEDERATED          | NO      | Federated MySQL storage engine                             | NULL         | NULL | NULL       |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
1 rows in set (0.00 sec)

Open my.cnf in your favorite editor and add ‘federated’ to the ‘[mysqld]‘ portion.

[mysqld]
federated
mysql> show engines;
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                    | Transactions | XA   | Savepoints |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| FEDERATED          | YES     | Federated MySQL storage engine                             | NO           | NO   | NO         |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
1 rows in set (0.00 sec)

Congrats!


Cross-Server Database Pollination

Background

In my lab, I have two servers running instances of MySQL. One of the servers acted as a development, and the other was staging/production. When playing around with some updates and upgrades for some time killers, I found the need to copy some of the tables automatically from a Cron job, with no user input.

I played around with some options such as SSH and replication, but neither were exactly what I was looking for.

I ended up using the following which would copy the database table from the remote host and execute it in the active machines mysql space.

mysqldump --protocol=TCP -h <REMOTE IP> -u <USER> -p'<PASS>' <DATABASE> <TABLE> | mysql -u <USER> -p’<PASSWORD>' <DATABASE>

If you omit the table from the first command, it will export the whole database.

Note: These two remote servers talk across an encrypted VLAN so I don’t stress too much on security here. If you need to, you could always tunnel the MySQL connection to add a simple layer of security.