Download, configure, compile, and install MySQL 5.5 from source code on Linux

MySQL 5.5 is the latest production-ready release of the most popular opensource database management system on the planet ie. MySQL.

In this tutorial, I am going to tell you how to download, configure, compile, and install MySQL 5.5 from source code on a Linux machine. You can read my tutorial "Install MySQL Server 5.0 and 5.1 from source code" for previous versions of MySQL server. Also, you can find instructions on how to download and install MySQL 5.6 here. Please prepare yourself to install several libraries on the server before installing MySQL 5.5. Luckily, I have already written about those libraries in my previous tutorials.

Please make sure you check the downloaded file's integrity before unzipping it. '#' (w/o quotes) in front of commands below means you have to run the commands as root user (or use sudo ).

Here are the libraries and softwares you need to install alongwith their installation tutorials (some tutorials are outdated ie. they are for older versions of libraries, so try finding the latest stable releases for all software systems and libraries before installing). In any case, you should try using properly tested binaries that come with your OS distribution (recommended for production):

Installing libaio on Linux:

InnoDB Plugin 1.1 (default in MySQL 5.5) now uses asynchronous I/O on Linux systems. This change introduces a dependency on libaio.

$ cd /opt
$ wget http://www.morphisms.net/~wkj/download/libaio.tbz
$ bunzip2 libaio.tbz
$ tar xf libaio.tar

After installing all these software, let's begin with the actual server installation process.

Download and extract MySQL 5.5.8:

Please make sure you check file's integrity after downloading (before installing).

$ wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.8.tar.gz/from/http://mysql.llarian.net/
$ tar xzf mysql-5.5.8.tar.gz
$ cd mysql-5.5.8

Configure and compile MySQL 5.5.8:

Please make sure you replace path locations according to your environment in commands below (if you are following my earlier tutorials for installation of required libraries then it is quite possible that you installed them under /usr/local/, if so please adjust the path in command below):

$ PATH=$PATH:/opt/bison/bin   #bison binary should be in your path

$ /opt/cmake/bin/cmake . -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/opt/mysql-5.5.8/data/ \
-DCMAKE_INSTALL_PREFIX=/opt/mysql-5.5.8 -DCURSES_LIBRARY=/opt/ncurses/lib/libncurses.a \
-DCURSES_INCLUDE_PATH=/opt/ncurses/include/ -DHAVE_LIBAIO_H=/opt/libaio/include/ \
-DINSTALL_LAYOUT=STANDALONE -DENABLED_PROFILING=ON \
-DMYSQL_MAINTAINER_MODE=OFF -DWITH_DEBUG=OFF \
-DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=TRUE -DWITH_ZLIB=bundled

$ make

Install MySQL 5.5.8:

# make install

You can initialize the server you just installed by using the instructions explained in Initializing MySQL database after installation.

Did this tutorial help a little? How about buy me a cup of coffee?

Buy me a coffee at ko-fi.com

Please feel free to use the comments form below if you have any questions or need more explanation on anything. I do not guarantee a response.

IMPORTANT: You must thoroughy test any instructions on a production-like test environment first before trying anything on production systems. And, make sure it is tested for security, privacy, and safety. See our terms here.

Comments (write a comment):

I have previously used the following to "build the client only" on a server:

./configure --without-server

What is the equivalent for cmake in 5.5.8 ? Posted by: Laura on Dec 21, 2010

@Laura

cmake .
make mysqlclient libmysql

This will produce for both static and shared libraries. mysqlclient is static client target, and libmysql is shared target.

The trick is just to pass the correct
target to make.

-DWITHOUT_SERVER=1 used to work at one point in the past. since it is not regularly tested, it got broken I believe. Posted by: Vladislav V on Dec 22, 2010

It's a very nice tutorial that I have ever found.

Thanks to the writer. Posted by: Laura on Dec 23, 2010

I have followed the above tutorial and I am able to run it properly by running mysqld and it is listening at 3306 port

but when I issued the following command , it doesn't
shows the mysql> prompt, there is no error in log file.

[root@ws-test mysql-5.5.8]# bin/mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with
; or \g.
Your MySQL connection id is 2
Server version: 5.5.8 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights eserved.
Oracle is a registered trademark of Oracle Corporation
and/or its affiliates. Other names may be trademarks of their respective
owners.


Segmentation fault

[root@ws-test mysql-5.5.8]#

Don't know what to do.Please help.


Thanks & Regards

Adarsh Sharma Posted by: Adarsh on Dec 24, 2010

Did you try connecting to the new MySQL instance using some other method e.g. Query Browser, Administrator, PHP etc.?

Please let me know.

thanks. Posted by: Shahryar G on Dec 25, 2010

U followed all earlier tutorials

and i got the error message

CMake Error: The source directory "/usr/local/mysql" does not appear to contain CMakeLists.txt. Posted by: Mohamed on Dec 30, 2010

something is wrong with your paths, please make sure you used the right path settings since in previous tutorials the path used for installation was /usr/local/ and in recent tutorials it was /opt/ and I indicated in the tutorial:

"Please make sure you replace path locations according to your environment in commands below (if you are following my earlier tutorials for installation of required libraries then it is quite possible that you installed them under /usr/local/, if so please adjust the path in command below)"

please paste the commands you used, if you are unable to resolve it

Thanks. Posted by: Shahryar G on Dec 31, 2010

i just changed the path of mysql to /usr/loca/mysql
but all other path as same as your installation i need to ask you question the mysql source does it contain CMakeLists.txt or it created with your last command

many thanks Posted by: mohamed on Jan 03, 2011

this command i used

/opt/cmake/bin/cmake . -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/mysql/data/ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DCURSES_LIBRARY=/opt/ncurses/lib/libncurses.a -DCURSES_INCLUDE_PATH=/opt/ncurses/include/ -DHAVE_LIBAIO_H=/opt/libaio/include/ -DINSTALL_LAYOUT=STANDALONE -DENABLED_PROFILING=ON -DMYSQL_MAINTAINER_MODE=OFF -DWITH_DEBUG=OFF Posted by: mohamed on Jan 03, 2011

CMake Error: The source directory "/usr/local/mysql" does not appear to contain CMakeLists.txt.
i want to know how to solve this problem.
Posted by: Al.Lee on Jan 03, 2011

I found the file in MySQL source code root directory, extracted a new source and found the file in the root.

May be you are not running the cmake command from inside your MySQL source directory, is that correct? Please make sure you do the following after extracting the source files

$ cd mysql-5.5.8 Posted by: Shahryar G on Jan 03, 2011

the problem seems that the source directory doesn't contain CMakeLists.txt
file all i need to know this file is already
exist in source code or we must create it
thanks for all help me to solve this issue Posted by: mohamed on Jan 04, 2011

yes, it does exist in the source files that you download from mysql.com Posted by: Shahryar G on Jan 04, 2011

thank you Shahryar the problem from
downloaded version Posted by: mohamed on Jan 05, 2011

Thanks for sharing.
Did Mysql's developers decide to remove "./configure" script ?if so,what is the reason? because that way was very simple.
Thanks in advance Posted by: nima0102 on Jan 16, 2011

To answer question from nima0102, there are at least 2 reasons I can think of why Oracle would want to change from 'configure' to 'cmake' in mysql build:

1. portable: cmake was intended to work with windows (MS-VC, Cygwin, Mingw, etc) and the UNIX (OSX, Linux, Solaris, etc.)
2. cmake tool comes from one package as oppose to configure is part of GNU tool chain called autotools (notice the 's' for plural). Autotools, as the name implied, consists of auttoconfig, automake, M4, and others. Autotools only work in GNU environment. Posted by: Steven on Feb 01, 2011

best linux application installation tutorial ive ever found... Posted by: purinda on Feb 09, 2011

Awesome walkthrough, I'm glad I stumbled upon this website while looking for answers regarding the dismissal of autotools. It's weird, I remember that a week ago I was able to download a MySQL source archive on my Windows 7 partition and use them via Cygwin.
I have no clue what happened exactly since then. Posted by: Klaus on Mar 02, 2011

I followed this tutorial step by step. After the make command it gives an error here:

[ 71%] Building CXX object libmysql/CMakeFiles/libmysql.dir/libmysql_exports_file.cc.o

Linking CXX shared library libmysqlclient.so
make[2]: *** [libmysql/libmysqlclient.so.16.0.0] Error 1
make[1]: *** [libmysql/CMakeFiles/libmysql.dir/all] Error 2


How do I resolve this? Posted by: sabman on Mar 07, 2011

Thanks a lot friend. Posted by: Sumith on Nov 01, 2011

i am trying to build mysql 5.5.17 using these commands :-

cmake . -DCMAKE_INSTALL_PREFIX=/servertools/mysql -DMYSQL_DATADIR=/var/lib/mysql

make

make install

but i am getting this error when i do "make install" :-
.
.
.
Up-to-date: /servertools/mysql/bin/mysqlslap
-- Installing: /servertools/mysql/bin/mysqld
CMake Error at sql/cmake_install.cmake:41 (FILE):
file INSTALL cannot copy file "/usr/local/src/mysql-5.5.17/sql/mysqld" to
"/servertools/mysql/bin/mysqld".
Call Stack (most recent call first):
cmake_install.cmake:95 (INCLUDE)


make: *** [install] Error 1 Posted by: manmohan on Nov 08, 2011

@sabman: there appears to be a library linking issue.

please give more details about the steps you followed and your system configuration (OS version etc.). Posted by: Shahryar G on Apr 23, 2012

cmake stop due to /usr/lib/libncurses.so', needed by `client/mysql' while installing MySQL 5.5 on Linux .

So please help me to solve this issue . very urgent Posted by: Anish K on Dec 02, 2012

@Anish,
You need to install ncurses before running cmake and provide the correct path to ncurses

see http://www.geeksww.com/tutorials/operating_systems/linux/tools/how_to_download_compile_and_install_gnu_ncurses_on_debianubuntu_linux.php Posted by: shahryar on Dec 05, 2012

Thanks, very much, very informative. Can you please elabortae if I have to build a rpm from the above so that if I install the rpm on other servers, I can install mysql in /opt/mysql, how can I do this?

Thanks Posted by: Rick on Mar 21, 2013

thanks alot friend Posted by: supeng on Oct 05, 2013

I want to download MySQL source code and install it. How i can do that? Posted by: Mukti G on Jul 11, 2015

@Mukti: Follow the instructions and change version number to latest available Posted by: syed on Jul 28, 2015

leave a comment on tutorial leave a comment