Quickshiftin - Clever Crazy Code

Installing the MySQL PREG plugin on Ubuntu with apt-get

December 1st, 2011


In our article several months ago we discovered the the PREG plugin for MySQL and realized there were no Ports in the mainline repository for Macports. Back then we shared our install instructions and now we find a need to install MySQL PREG on Ubuntu.

Installing MySQL PREG

The process on Ubuntu is a bit more direct, start off by installing everything except the plugin itself from apt.

sudo apt-get update
sudo apt-get install build-essential libmysqld-dev libpcre3-dev

Then build the plugin from source.

cd ~
wget http://www.mysqludf.org/lib_mysqludf_preg/lib_mysqludf_preg-1.0.1.tar.gz
tar -xzf lib_mysqludf_preg-1.0.1.tar.gz
cd lib_mysqludf_preg-1.0.1
make install

Activating the plugin

Read our original article for more details, but once the plugin has been compiled and installed, it needs to be activated. Simply login to your database and run the following:

USE mysql;
CREATE FUNCTION lib_mysqludf_preg_info RETURNS STRING SONAME 'lib_mysqludf_preg.so';
CREATE FUNCTION preg_capture RETURNS STRING SONAME 'lib_mysqludf_preg.so';
CREATE FUNCTION preg_check RETURNS INTEGER SONAME 'lib_mysqludf_preg.so';
CREATE FUNCTION preg_replace RETURNS STRING SONAME 'lib_mysqludf_preg.so';
CREATE FUNCTION preg_rlike RETURNS INTEGER SONAME 'lib_mysqludf_preg.so';
CREATE FUNCTION preg_position RETURNS INTEGER SONAME 'lib_mysqludf_preg.so';


Installing the PREG plugin is rather straightforward on Ubuntu. The plugin does offer more powerful regex support for MySQL than the stock POSIX compliant REGEX family of functions. If you find yourself needing the plugin on Ubuntu, we hope this article saves you a few minutes on the install.


If you enjoyed this post please consider sharing it!

  • Twitter
  • LinkedIn
  • Facebook
  • Reddit
  • Digg

Leave a Response