Creating A Portable MySQL On CentOS 6 And Ubuntu 11.10 Linux From Sources

Want to support HowtoForge? Become a subscriber!
Submitted by eduardo.lago.aguiar (Contact Author) (Forums) on Mon, 2012-02-27 19:36. :: CentOS | Ubuntu | MySQL

Creating A Portable MySQL On CentOS 6 And Ubuntu 11.10 Linux From Sources

This tutorial shows how to create a portable MySQL installation on GNU/Linux. It applies to:

  • MySQL 5.5.19
  • CentOS 6.x / Ubuntu 11.10 Oneiric Ocelot

At the end of this guide you will obtain a portable MySQL installation on a target directory with its own databases, binaries, logs, pid files, etc.  Consider always the use of a permission preserving packaging (like TAR) for moving the installation between systems or removable storages.





  1. Define some environment variables to make the installation smoothly:

    $ TARGET=$HOME/mysql
    $ BASEDIR=$TARGET/usr/local/mysql
    $ DATADIR=$TARGET/usr/local/mysql/data
    $ PORT=9797
    $ VERSION=5.5.19

  2. Install cmake, ncurses and bison:
    • On CentOS:

      $ sudo yum install cmake ncurses-devel bison

    • On Ubuntu:
    • $ sudo apt-get install cmake libncurses5-dev bison

  3. Unpack and make (NOTE: mysql-5.5.19.tar.gz is already downloaded in /tmp):

    $ pushd /tmp
    $ tar zxvf mysql-${VERSION}.tar.gz
    $ cd mysql-${VERSION}
    $ cmake .
    $ make

  4. Install into target directory:

    $ mkdir -p $TARGET
    $ make install DESTDIR="$TARGET"

  5. Create system databases:

    $ pushd $BASEDIR
    $ scripts/mysql_install_db --user=$USER \
    --basedir=$BASEDIR \
    --datadir=$DATADIR \
    $ mkdir -p $TARGET/var/run/mysql
    $ mkdir -p $TARGET/var/log/mysql
    $ popd
    $ popd


Post Install Steps

  • Running the portable MySQL (NOTE: bind-address is settled to, it means listening on all network interfaces, you can change it to for local connections only or to an specific network interfaces address like

    $ $BASEDIR/bin/mysqld_safe --user=$USER \
    --basedir=$BASEDIR \
    --datadir=$DATADIR \
    --pid-file=$TARGET/var/run/mysql/ \
    --skip-syslog \
    --log-error=$TARGET/var/log/mysql/mysql.err \
    --port=$PORT \
    --socket=$TARGET/var/run/mysqld/mysqld.sock \
    --ledir=$BASEDIR/bin \
    --mysqld=mysqld \

  • Connecting locally (via socket) to the portable MySQL:

    $ $BASEDIR/bin/mysql -u root --socket=$TARGET/var/run/mysqld/mysqld.sock

  • Creating a sample database and granting all privileges to a user:

    $ $BASEDIR/bin/mysql -u root --socket=$TARGET/var/run/mysqld/mysqld.sock <<EOT
    create database alfresco;
    grant all privileges on alfresco.* to alfresco@'%' identified by 'alfresco';

  • Connecting remotely to the created database (NOTE: verify firewall settings on the server before connecting remotely):

    $ mysql -u alfresco -h SERVER --port=9797 -p alfresco

  • Changing the root password:

    $ $BASEDIR/bin/mysqladmin -u root password 'root' --socket=$TARGET/var/run/mysqld/mysqld.sock

Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Mon, 2012-02-27 20:04.


Finally  a short and conscious description of everything one needs to know to build from sources. If you read from other sources, the half of the post consists of -D parameters for cmake call :)