Percona on FreeBSD

As of 2012-10-26, Percona (a fork of the MySQL database server) isn't in the FreeBSD ports system. Unfortunatelly, Percona doesn't build out of the box on FreeBSD 9.0 amd64. Instead, you have to follow these steps:

  1. Install cmake:
    sudo make -C /usr/ports/devel/cmake install clean
  2. Install bison:
    sudo make -C /usr/ports/devel/bison install clean
  3. Download the source code of Percona from http://www.percona.com/software/percona-server/downloads/. I used Percona-Server-5.5.27-rel29.0.tar.gz.
  4. Download my patches: Percona-Server-5.5.27-rel29.0.FreeBSD_9_0.patch and mysql-server.percona.patch
  5. Unpack the source code of Percona:
    tar xzf Percona-Server-5.5.27-rel29.0.tar.gz
  6. Apply my patch:
    cd Percona-Server-5.5.27-rel29.0
    patch -p1 <../Percona-Server-5.5.27-rel29.0.FreeBSD_9_0.patch
  7. Prepare the build process. I recommend the following options (don't forget the trailing dot!):
    cmake -D WITH_ARCHIVE_STORAGE_ENGINE:BOOL=y -D WITH_FEDERATED_STORAGE_ENGINE:BOOL=y -D WITH_READLINE:BOOL=y -D WITH_SSL:STRING=system -D CMAKE_INSTALL_PREFIX:STRING=/usr/local/percona .
  8. Build Percona:
    make
  9. Install Percona:
    sudo make install
  10. Adjust your search path (add this to your ~/.bash_profile, too):
    export PATH=$PATH:/usr/local/percona/bin
  11. Create a group, a user and a home directory for Percona. We'll honor that it's a MySQL clone:
    sudo pw groupadd mysql -g 88
    sudo pw useradd mysql -u 88 -g mysql -c "MySQL Daemon" -d /var/db/mysql -s /usr/sbin/nologin
    sudo mkdir -m 0750 /var/db/mysql
    sudo chown mysql:mysql /var/db/mysql
  12. Take MySQL's rc script:
    sudo cp usr/ports/databases/mysql55-server/files/mysql-server.in /usr/local/etc/rc.d/mysql-server
    sudo chmod 0755 /usr/local/etc/rc.d/mysql-server
  13. Adjust that rc script:
    cd /usr/local/etc/rc.d
    sudo patch -p0 < ~/mysql-server.percona.patch
    sudo rm mysql-server.orig
  14. Add the following line to /etc/rc.conf:
    mysql_enable="YES"
  15. Optionally, create a config file for Percona. That's beyond the focus of this howto. Try your favorite search engine and your prefered book store for that. As a bare minimum, I recommend putting the following into /var/db/mysql/my.cnf if you're going to use the InnoDB storage engine:
    [mysqld]
    innodb_file_per_table = 1
    innodb_log_files_in_group = 2
    innodb_log_file_size = 256M
    
  16. Finally, start Percona:
    /usr/local/etc/rc.d/mysql-server start
  17. Now secure, tune, and load some data into your database!