MariaDB [(none)]> INSTALL SONAME ‘ha_connect.so’; ERROR 1126 (HY000): Can’t open shared library ‘/usr/lib64/mysql/plugin/ha_connect.so’ (errno: 2, libodbc.so.1: cannot open shared object file: No such file or directory) MariaDB [(none)]> exit
ln -s libodbc.so.2 libodbc.so.1Now the installation works:
MariaDB [(none)]> INSTALL SONAME ‘ha_connect.so’; Query OK, 0 rows affected (0.01 sec)(On Ubuntu, it is possible to use “apt-get install libodbc1” and it appears on Centos you can also use “yum install unixODBC-libs” to install the same.) Here’s the daily export using the mongoexport tool:
mongoexport –db test –collection restaurants –out /var/lib/mysql/test/restaurants.json –jsonArrayThe jsonArray flag is important, so the output is formatted the way the CONNECT engine is expecting it. Also, place the export within the relevant database directory inside /var/lib/mysql. Snippet of exported file (manually pretty-printed):
{
“_id” : ObjectId(“580cda5aaf1de8b908ccfe40”),
“address” : { “building” : “522”, “coord” : [ -73.95171, 40.767461 ], “street” : “East 74 Street”, “zipcode” : “10021” },
“borough” : “Manhattan”,
“cuisine” : “American”,
“grades” : [ { “date” : ISODate(“2014-09-02T00:00:00Z”), “grade” : “A”, “score” : 12 }, { “date” : ISODate(“2013-12-19T00:00:00Z”), “grade” : “B”, “score” : 16 }, { “date” : ISODate(“2013-05-28T00:00:00Z”), “grade” : “A”, “score” : 9 }, { “date” : ISODate(“2012-12-07T00:00:00Z”), “grade” : “A”, “score” : 13 }, { “date” : ISODate(“2012-03-29T00:00:00Z”), “grade” : “A”, “score” : 11 } ],
“name” : “Glorious Food”,
“restaurant_id” : “40361521”
}
use test; create table restaurants engine=connect table_type=JSON file_name=‘restaurants.json’ option_list=‘level=1’; MariaDB [test]> show create table restaurants\G Table: restaurants Create Table: CREATE TABLE `restaurants` ( `id$oid` char(24) NOT NULL `FIELD_FORMAT`=’_id:$oid’, `address_building` char(9) NOT NULL `FIELD_FORMAT`=‘address:building’, `address_coord` varchar(256) DEFAULT NULL `FIELD_FORMAT`=‘address:coord’, `address_street` char(38) NOT NULL `FIELD_FORMAT`=‘address:street’, `address_zipcode` char(5) NOT NULL `FIELD_FORMAT`=‘address:zipcode’, `borough` char(13) NOT NULL, `cuisine` char(64) NOT NULL, `grades` char(1) DEFAULT NULL, `grades_date` varchar(256) DEFAULT NULL `FIELD_FORMAT`=‘grades::date’, `grades_grade` char(14) DEFAULT NULL `FIELD_FORMAT`=‘grades::grade’, `grades_score` bigint(2) DEFAULT NULL `FIELD_FORMAT`=‘grades::score’, `name` char(65) NOT NULL, `restaurant_id` char(8) NOT NULL ) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`=‘JSON’ `FILE_NAME`=‘restaurants.json’ `OPTION_LIST`=‘level=1’
create table proprietors ( restaurant_id char(80), owner char(128) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;Now I can run my daily report of new inspections recorded in MongoDB, linked to randomly generated owner names:
MariaDB [test]> select proprietors.owner, restaurants.name, grades_grade from proprietors, restaurants where proprietors.restaurant_id=restaurants.restaurant_id and grades_date>‘2015-01-08’ and grades_grade in(‘A’,‘B’); +———————+————————————————+————–+ | owner | name | grades_grade | +———————+————————————————+————–+ | Treva Tullis | Bagels N Buns | A | | Maud Morningstar | La Fusta Restaurant | A | | Vanessa Vowell | The Greek Corner | A | | Teressa Truex | Mcdonald’S | A | | Eli Enright | Neron’S Pizza | A | | Cruz Cypert | Mcdonald’S | A | | Beatrice Bramlett | Sidewalk Bar & Restaurant | A | | Roscoe Rapozo | Tortilla Flats | A | | Justa Jasik | Veselka Restaurant | A | | Eliza Edmundson | Dakota Diner | A | | Becky Branson | Arturo’S Pizza | A | | Beatrice Bramlett | Areo Restaurant | A | | Mariko Moos | Pomodoro Ristorante | A | | Chae Champine | Miracali Bakery | A | …Once everything is set up, this is a quick way to merge data from heterogenous data sources, and a reasonable solution for a reporting application. Thank you to Abhinav Gupta for the technical review.
Ready to optimize your MySQL Database for the future?