Generic Build Instructions
The instructions on this page will help you compile MariaDB from source. Links to more complete instructions for specific platforms can be found on the source page.
First, get a copy of the MariaDB source.
Next, prepare your system to be able to compile the source.
If you don't want to run MariaDB as yourself, then you should create a
mysql user. The example below uses this user.
MariaDB 5.5 and above is compiled using cmake.
It is recommended to create a build directory beside your source directory
mkdir build-mariadb cd build-mariadb
NOTE If you have built MariaDB in the past and have recently updated the repository, you should perform a complete cleanup of old artifacts (such as cmake configured files). In the base repository run:
git clean -xffd && git submodule foreach --recursive git clean -xffd
You can configure your build simply by running cmake without any special options, like
server is where you installed MariaDB. If you are building in the source directory, just omit
If you want it to be configured exactly as a normal MariaDB server release is built, use
cmake ../server -DBUILD_CONFIG=mysql_release
This will configure the build to generate binary tarballs similar to release tarballs from downloads.mariadb.org. Unfortunately this doesn't work on old platforms, like OpenSuse Leap 15.0, because MariaDB binary tarballs are built to minimize external dependencies, and that needs static libraries that might not be provided by the platform by default, and would need to be installed manually.
To do a build suitable for debugging use:
cmake ../server -DCMAKE_BUILD_TYPE=Debug
By default, MariaDB is compiled with the
-Werror flag, which causes compiling to abort
if there is a compiler warning. You can disable that by configuring with
cmake ../server -DCMAKE_BUILD_TYPE=Debug -DMYSQL_MAINTAINER_MODE=OFF.
All cmake configuration options for MariaDB can be displayed with:
cmake ../server -LH
To build and install MariaDB after running cmake use
cmake --build . sudo cmake --install .
If the commands above fail, you can enable more compilation information by doing:
cmake --build . --verbose
If you want to generate a binary tarball, run
Using BUILD Scripts
There are also
BUILD scripts for the most common systems for those that doesn't want to dig into cmake options. These are optimized for in source builds.
The scripts are of type 'compile-#cpu#-how_to_build'. Some common scripts-are
|compile-pentium64||Compile an optimized binary optimized for 64 bit pentium (works also for amd64)|
|compile-pentium-debug||Compile a debug binary optimized for 64 bit pentium|
|compile-pentium-valgrind-max|| Compile a debug binary that can be used with valgrind to find wrong memory accesses and memory leaks. Should be used if one want's to run the |
Some common suffixes used for the scripts:
|Compile for 32 bit cpu's|
|Compile for 64 bit cpu's|
|Enable (almost) all features and plugins that MariaDB supports|
|binary is compiled with profiling (gcc --pg)|
|binary is compiled with code coverage (gcc -fprofile-arcs -ftest-coverage)|
|The binary is compiled for debugging and optimized to be used with valgrind.|
| The binary is compiled with all symbols (gcc -g) and the |
BUILD scripts support the following options:
|-h, --help||Show this help message.|
|-n, --just-print||Don't actually run any commands; just print them.|
|-c, --just-configure||Stop after running configure. Combined with --just-print shows configure options.|
|--extra-configs=xxx||Add this to configure options|
|--extra-flags=xxx||Add this C and CXX flags|
|--extra-cflags=xxx||Add this to C flags|
|--extra-cxxflags=xxx||Add this to CXX flags|
|--verbose||Print out full compile lines|
|--with-debug=full||Build with full debug(no optimizations, keep call stack).|
A typical compilation used by a developer would be:
This configures the source for debugging and runs make. The server binary will be
Starting MariaDB for the First Time
After installing MariaDB (using
sudo make install), but prior to starting MariaDB for the first time, one should:
- ensure the directory where you installed MariaDB is owned by the mysql user (if the user doesn't exist, you'll need to create it)
- run the
mysql_install_dbscript to generate the needed system tables
Here is an example:
# The following assumes that the 'mysql' user exists and that we installed MariaDB # in /usr/local/mysql chown -R mysql /usr/local/mysql/ cd /usr/local/mysql/ scripts/mysql_install_db --user=mysql /usr/local/mysql/bin/mysqld_safe --user=mysql &
If you want to test your compiled MariaDB, you can do either of:
Run unit tests:
cmake --build . --target test
Or run mtr tests:
Each of the above are run from the build directory. There is no need to '
cmake --install .' MariaDB prior to running them.
NOTE: If you are doing more extensive testing or debugging of MariaDB (like with real application data and workloads) you may want to start and run MariaDB directly from the source directory instead of installing it with '
sudo make install'. If so, see
Running MariaDB from the Source Directory.
Increasing Version Number or Tagging a Version
If you have made code changes and want to increase the version number or tag our version with a specific tag you can do this by editing the
VERSION file. Tags are shown when running the '
mysqld --version' command.
MariaDB builds with
readline; using an alternative such as
Editline may result in problems with non-ascii symbols.