How to switch between different installed MariaDB versions
Contents
- Stopping a pre-installed MySQL/MariaDB from interfering with your tests
- How to create a binary distribution (tar file)
- Creating a directory structure for the different installations
- Setting up the data directory
- Running a MariaDB server
- Setting up a .my.cnf file for running multiple MariaDB main versions
This article is about how to manage many different installed MariaDB version and running them one at a time. This is useful when doing benchmarking, testing or developing different MariaDB versions.
This is most easily done by using tar files from the downloads area.
Stopping a pre-installed MySQL/MariaDB from interfering with your tests
If MySQL/MariaDB is already installed and running, you have two options:
- Use the test MariaDB servers with a different port & socket.
- In this case you are probably best of by creating a specific section for MariaDB in your
~/.my.cnf
file.
- In this case you are probably best of by creating a specific section for MariaDB in your
- Take down mysqld with
/etc/rc.d/mysql stop
ormysqladmin shutdown
. Note that you don't have to deinstall MySQL!
How to create a binary distribution (tar file)
Here follows first a short description of how to generate a tar file from a source distribution. If you have downloaded a tar file, you can skip this section.
The steps to create a tar file is:
- Decide where to put the source. A good place is under
/usr/local/src/mariadb-5.#
. - Get the source
- Compile the source
- Create the binary tar ball.
Then you will be left with a tar file with something like:
mariadb-5.3.2-MariaDB-beta-linux-x86_64.tar.gz
Creating a directory structure for the different installations
Install the binary tar files under /usr/local/
with
the following directory names:
mariadb-5.1
mariadb-5.2
mariadb-5.3
The above assumes you are just testing major version. If you want to have
specific versions, use directory names like mariadb-5.3.2
Then add a link from the directory you want to use just now to
mariadb
. This allows you to easily move between different
installations by just changing the link.
Example:
cd /usr/local tar xfz /tmp/mariadb-5.3.2-MariaDB-beta-linux-x86_64.tar.gz mv mariadb-5.3.2-MariaDB-beta-linux-x86_64 mariadb-5.3 ln -s mariadb-5.3 mariadb
Setting up the data directory
You have the options of either using a shared database directory or
creating a unique database directory per server. For testing, a
common directory is probably easiest. Note that you can only have one
mysqld
server running against one data directory.
Setting up a common data directory
The steps are:
- Create the
mysql
system user if you don't have it already! (On Linux you do it with theuseradd
command). - Creating the directory (belove we call it
mariadb-data
) or adding a symlink to a directory on some other place. - Create the
mysql
permission tables withmysql_install_db
cd /usr/local/ mkdir mariadb-data cd mariadb ./bin/mysql_install_db --no-defaults --datadir=/usr/local/mariadb-data chown -R mysql mariadb-data mariadb-data/*
The reason to use --no-defaults
is to ensure that we don't
get wrong options from some old my.cnf.
Setting up different data directories
To create a different data
directory for each installation:
cd mariadb ./bin/mysql_install_db --no-defaults chown -R mysql mariadb-data mariadb-data/*
This will create a directory data
inside the
current directory.
If you want to use another disk you should do:
cd mariadb ln -s path-to-empty-directory-for-data data ./bin/mysql_install_db --no-defaults --datadir=./data chown -R mysql mariadb-data mariadb-data/*
Running a MariaDB server
The normal steps are:
rm mariadb ln -s mariadb-5.# mariadb cd mariadb ./bin/mysqld_safe --no-defaults --datadir=/usr/local/mariadb-data &
Setting up a .my.cnf file for running multiple MariaDB main versions
If you are going to start/stop MariaDB a lot of times, you should create
a ~/.my.cnf
file for the common options you are using.
The following example show how you to use a non-standard TCP-port and socket (to not interfere with a main MySQL/MariaDB server) and how to setup different options for each main server:
[client] socket=/tmp/mysql.sock port=3306 [mysqld] socket=/tmp/mysql.sock port=3306 datadir=/usr/local/mariadb-data [mariadb-5.2] # Options for MariaDB 5.2 [mariadb-5.3] # Options for MariaDB 5.3
If you create an ~/.my.cnf
file, you should start mysqld
with --defaults-file=~/.my.cnf
instead of --no-defaults
in the examples above.