MySQL Proxy

Icon


Contents:

1   Overview
2   Building MySQL Proxy
3   Testing MySQL Proxy
  Related pages






1. Overview.

This document is intended for Linux developers. If you notice mistakes, write to: oldcoder@yahoo.com

MySQL Proxy is a software interface layer that runs between a MySQL client and one or more MySQL “back end” servers. It can be configured so as to act as a single virtual MySQL server that happens to distribute its data internally across multiple back ends. This makes it a possible candidate for the basis of a database sharding framework.

This document explains how I got MySQL Proxy to work on a Debian (Ubuntu) system. Note: All steps were done as superuser except where otherwise indicated.

The procedure used may or may not work for newer releases of Debian and/or Ubuntu. However, it's discussed here in the hope that it may be useful.





2. Building MySQL Proxy.

2.1. I started with a Debian (Ubuntu) machine that I'd configured as a development system previously.

For the Debian setup steps that I used, or reasonably compatible steps, click here.

2.2. I went to a downloads directory and downloaded a current MySQL Proxy source tarball using the link below. This copy of the link goes to a local copy of the tarball. Therefore it should work:

ftp://mirror.switch.ch/mirror/mysql/\
Downloads/MySQL-Proxy/mysql-proxy-0.8.3.tar.gz

2.3. I unpacked the source tarball and entered the top-level source directory:


tar zxf mysql-proxy-0.8.3.tar.gz
cd      mysql-proxy-0.8.3

2.4. I terminated any existing MySQL Proxy instance:


killall -qw mysql-proxy

2.5. I configured, built, and installed the associated software:


sh ./configure \
    --prefix=/opt \
    --enable-shared=yes \
    --enable-static=no \
    --mandir=/opt/man

make && make install

At this point, installation of the MySQL Proxy core software was believed to be completed.





3. Testing MySQL Proxy.

The next goal was to do a smoke-test of MySQL Proxy.

3.1. I created a text file named /tmp/first.lua and added the following Lua code:


function read_query(packet)
   if string.byte(packet) == proxy.COM_QUERY then
        print("DEBUG query: "
        .. string.sub(packet, 2))
    end
end

Note: Lua code was used because this is how SQL Proxy works. SQL Proxy runs Lua functions to process and/or modify data.

3.2. I started an instance of the MySQL Proxy daemon as follows:


/opt/bin/mysql-proxy \
    --proxy-lua-script=/tmp/first.lua --daemon

and did the following MySQL command, replacing ROOTPASS with the root password for the local copy of MySQL:


mysql -u root -p'ROOTPASS' \
      -h 127.0.0.1 -P 4040 -e 'SHOW TABLES FROM test'

This produced the following output, which seemed to confirm that the daemon was working:


DEBUG query: select @@version_comment limit 1
DEBUG query: SHOW TABLES FROM test





For acknowledgments related to CSS and other code used, click here.

Linked or embedded works (software, books, articles, etc.) are presented under their own licenses.

Other unique content on this page, excluding screenshots, is distributed under the following license: C.C. Attribution NonCommercial ShareAlike 3.0. In some cases, screenshots are distributed under the same license. In other cases, the associated program's license applies.

image Valid XHTML 1.0