HowTo: Install Percona Server

As I promised in the last post, I am going to show you how to install the MySQL-Server solution of Percona.

There are two ways of installing Percona Server: Via package manager or from source. Maybe some of you think that it is not needed to install Percona Server from source and they are right. It is not really needed, but it has some advantages which you will see later on. For the sake of completeness I will show both ways.

This HowTo is based on my personal purposes and needs, so there are other possibilities to get Percona running for sure.
My favourite operation systems are Debian and Ubuntu and I currently use Percona-Server v5.5.15-21.0, but will probably upgrade in some weeks.

I recommend at least basic knowledge of MySQL and UNIX to understand most of the things explained in the following part.

The two ways of installing Pecona Server:

  1. Installion via packet manager
  2. The only thing you have to do is getting the signed key of Percona and adding the repositories to your source list. With this you are able to install the software automatically via package manager.
    You will need root access to do following actions.

    # Get the key
    $ gpg --keyserver hkp://keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
    $ gpg -a --export CD2EFD2A | sudo apt-key add -

    # Add the repositories
    # Please replace $RELEASE with your current OS release below
    $ echo -e "\n# Percona Server\ndeb http://repo.percona.com/apt $RELEASE main\ndeb-src http://repo.percona.com/apt $RELEASE main" >> /etc/apt/sources.list

    After that you are ready to install Percona Server yet!

    $ apt-get install percona-server-server-5.5

  3. Installation from source
  4. This version is more complex, but you have the possibility to install the application for custom purposes.
    You will need root access to do following actions.

    # Add mysql user
    $ useradd -s /bin/false -b /opt/mysql -d /opt/mysql -m mysql

    # Install MySQL client
    $ apt-get install mysql-client-5.1

    I prefer installing the client previously, because it already creates the MySQL configuration files like the my.cnf in /etc/mysql/ which is not created by this installation method. Indeed Percona provides different versions of my.cnf files for different purposes, but I will topic this in another tutorial.

    Now we can start with the basic installation.

    # Install required packages
    $ apt-get install automake libtool g++ ncurses-dev bison

    # Get and extract Percona source
    $ wget http://www.percona.com/redir/downloads/Percona-Server-5.5/Percona-Server-5.5.15-21.0/source/Percona-Server-5.5.15-rel21.0.tar.gz
    $ tar xvfz Percona-Server-5.5.15-rel21.0.tar.gz
    $ cd Percona-Server-5.5.15-rel21.0

    # Prepare build
    $ sh BUILD/autorun.sh
    $ ./configure --without-plugin-innobase --with-plugin-innodb_plugin --prefix=/opt/mysql

    # Create directory for logging
    $ mkdir /var/log/mysql
    $ chown mysql:mysql /var/log/mysql

    I prefer to install MySQL in /opt/mysql, so you can specify this with the –prefix option. The two other options trigger the usage of XtraDB instead of the build-in InnoDB storage engine. I wrote something about this in my last article of Percona Server. For increasing InnoDB performance it is very important to use this!

    # Build the sources
    $ make -j
    $ make install

    # Install basic database
    $ cd /opt/mysql
    $ ./scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data --verbose --log-error=/tmp/mysql.error.log --defaults-file=/etc/mysql/my.cnf

    # Set MySQL user privileges
    $ chown -R mysql:mysql /opt/mysql

    If you followed these steps correctly you should have a database which is almost ready to run. We will now create some files to be able to start and stop MySQL server easily and provide correct startup and shutdown behaviour with OS actions.

    # Use Percona support files
    $ echo "/opt/mysql/support-files/mysql.server start" > /etc/init.d/mysql_start
    $ echo "/opt/mysql/support-files/mysql.server stop" > /etc/init.d/mysql_stop
    $ chmod 755 /etc/init.d/mysql_*

    # Link them to rc directories
    $ ln -s ../init.d/mysql_start /etc/rc2.d/S19mysql
    $ ln -s ../init.d/mysql_stop /etc/rc0.d/K21mysql
    $ ln -s ../init.d/mysql_stop /etc/rc6.d/K21mysql

    The last thing you have to do before startup are small adjustments to your MySQL configuration. There have to be some necessary changes to get this working correctly. The advantage of my.cnf is that it has an include path for custom configuration files. So let us use this due to the fact that the content of these files overwrite my.cnf options.

    # Add custom paths
    $ echo -e "[mysqld]\n\nbasedir = /opt/mysql\ndatadir = /opt/mysql/data\n" > /etc/mysql/conf.d/mysql_additon.cnf

    # Required XtraDB config
    $ echo -e "innodb_file_per_table = 1\ninnodb_file_format = barracuda" >> /etc/mysql/conf.d/mysql_additon.cnf

    I just set the correct base- and data-dir of MySQL, because I prefer this setting. It is up to you how handle this. The XtraDB configuration settings I did are really important! The first one (innodb_file_per_table) is set to 1 and used for reducing file access and therefore reducing I/O. This becomes more important if you have slow disks, but is recommended by me anyways. The second one (innodb_file_format) is set to barracuda, which is the only supported table format for XtraDB.

    Now you should be able to start and stop your MySQL server with following commands:

    # Start
    $ /etc/init.d/mysql_start
    # Stop
    $ /etc/init.d/mysql_stop

I hope this tutorial helped you to install and configure your Percona Server. If you have feedback, regards, corrections or questions please let me know and do not hesitate to comment!

Keep in mind that there will follow guides for MySQL performance tuning and a backup solution for InnoDB and MyISAM tables.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>