Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
MySQL 5.1 Plugin Development

You're reading from   MySQL 5.1 Plugin Development Extend MySQL to suit your needs with this unique guide into the world of MySQL plugins

Arrow left icon
Product type Paperback
Published in Aug 2010
Publisher Packt
ISBN-13 9781849510608
Length 288 pages
Edition 1st Edition
Tools
Arrow right icon
Toc

Table of Contents (16) Chapters Close

MySQL 5.1 Plugin Development
Credits
About the Authors
About the Reviewer
1. Preface
1. Compiling and Using MySQL Plugins 2. User Defined Functions FREE CHAPTER 3. Daemon Plugins 4. Information Schema Plugins 5. Advanced Information Schema Plugins 6. Full-text Parser Plugins 7. Practical Full-text Parsers 8. Storage Engine Plugins 9. HTML Storage Engine—Reads and Writes 10. TOCAB Storage Engine — Implementing Indexes Beyond MySQL 5.1

Plugin libraries


Building and installing plugin libraries is very much like building and installing UDFs. The include and library paths are the same but some further build options are needed. This is slightly complicated by the fact that some plugin types (namely Information Schema and Storage Engine plugins) require the MySQL source to be downloaded for the version of the MySQL server you have installed. This is so that the plugin can have access to data and functions that are only "half-public" and are not declared in the installed C header files.

Linux

When compiling on Linux and using just the normal plugin API we can compile in the same way as with UDFs:

gcc -omy_plugin.so my_plugin.c `mysql_config --cflags` -shared -fPIC -DMYSQL_DYNAMIC_PLUGIN

Notice that the main difference here is -DMYSQL_DYNAMIC_PLUGIN. This sets up the necessary environment for the plugin at compile time.

For plugins that require access to the MySQL server source, compiling is slightly different (suppose, the MySQL source tree is in /Sources/mysql‑5.1.35):

gcc omy_plugin.so my_plugin.cc `mysql_config cflags` —I/Sources/mysql 5.1.35/include/ I/Sources/mysql 5.1.35/regex —I/Sources/mysql 5.1.35/sql shared fPIC fno exceptions —fno rtti DMYSQL_DYNAMIC_PLUGIN

Typically, such a plugin will be in C++, not C. It is compiled exactly the same way the main server is—without exceptions or runtime type identification. Technically, it could use exceptions, but then it may need to use g++ instead of gcc as a C++ compiler. Either way, it needs extra include paths that point to the include/, regex/, and sql/ directories of the MySQL source tree.

Mac OS X

Just as in the UDF case, compiling plugins on Mac OS X is almost the same as on Linux. You can use the same command line and only replace ‑shared ‑fPIC with ‑bundle or bundle ‑Wl, ‑undefined ‑Wl,dynamic_lookup as explained before.

Windows

In Windows we can compile MySQL plugins that do not require the inclusion of the MySQL source code (everything except Information Schema and Storage Engine plugins) using a process very similar to compiling UDFs.

First, we need to create an empty project file to contain the source and build environment:

We can then add or create a .cpp file containing the source for our plugin:

This project needs to be a .dll, not an executable one. We can set this in the project's Property Pages dialog:

We now need to set up the C/C++ include paths so that the MySQL include path is in them:

This final step is different to compiling the UDFs. We need to add a C/C++ preprocessor definition so that the include files set up everything we need for a MySQL plugin. To do this we simply add MYSQL_DYNAMIC_PLUGIN to the definitions list:

Installing a plugin

Just as with UDFs, our MySQL plugin needs to be in plugin_dir before it can be added to MySQL. Once it is located there the syntax is very simple. All of the details about how to use the plugin are in the plugin itself. So we simply need:

INSTALL PLUGIN my_plugin SONAME 'my_plugin.so'
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image