Build mysql using Source Code

Hi, folks!

Think about a scenario, if we want to install a package we just type yum install <package> and which always downloads the latest package from repo.
In a scenario like a production environment or other infrastructure, We may install software from the source. Because we need a very specific version not available in your distribution repository, or we want to modify the program to fix a bug or add a feature. So, I will take this opportunity to give you a taste of the power you have at hand now that you are able to compile your own software.

In this blog, let's compile our own MySQL using source code.



Step 1: Install necessary packages on your system 
(My case, I am using Centos 7)
cmake3 - A tool for managing the build process of software using a compiler-independent method. 
make -  Used to build executable programs and libraries from source code
gcc  - (higher than 5.4)
gcc-c++
bison
ncurses
Ncurses-devel (devel is the development version)
patchelf - simple utility for modifying an existing ELF executable
[centos]# sudo yum -y install bison ncurses Ncurses-devel patchelf
# install cmake3
[centos]# sudo yum install centos-release-scl
[centos]# sudo yum install devtoolset-7
[centos]# scl enable devtoolset-7 bash
[centos]# gcc --version
gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Step 2: Download Source Code from dev.mysql.com
[centos]# cd /opt
[centos]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.21.tar.gz
[centos]# mkdir mysql
[centos]# tar -zxvf mysql-8.0.21.tar.gz
Note: Please choose the write source code for your environment and I am installing my sql to /opt/mysql directory

Step 3: Build MySQL using CMake3
Now cd into the extracted directory and start building our package
[centos]# cd mysql-8.0.21
[centos]# cmake3 -DCMAKE_INSTALL_PREFIX=/opt/mysql -DWITH_BOOST=./boost/boost_1.0
-DFORCE_INSOURCE_BUILD=1 -DWITH_SSL=/usr/local/ssl
-DMAKE_INSTALL_PREFIX define your desired path to install 
 -DWITH_BOOST = your boost path location (boost may inside your source code if not you have to download and define the path yourself). -DFORCE_INSOURCE_BUILD=1 to allow build binary inside the current directory.
Define ssl path -DWITH_SSL=/usr/local/ssl

Step 4: Compile and Install the executable binaries using make; make install
[centos]# make; make install
# patience, it take 2 hours to build
Step 5: Create MySQL group and user
[centos]# groupadd mysql
[centos]# useradd -g mysql mysql
#provide permission to mysql user
[centos]# chown -R mysql:mysql /opt/mysql
Step 6: Enable MySQL socket for MySQL server connection
[centos]# cd /opt/mysql
[centos]# vim my.cnf

[client]
port=3306
socket=/opt/mysql/mysql.sock

[mysqld]
port=3306
socket=/opt/mysql/mysql.sock

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/opt/mysql/mysqld.pid

Step 7: Initialize MySQL
[centos]# cd /opt/mysql
[centos]# bin/mysqld --initialize --user=mysql
2017-11-13T09:41:23.751963Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-13T09:41:26.623584Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-11-13T09:41:26.882632Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-13T09:41:27.014087Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d1c4626e-c856-11e7-a67a-000c292f80f2.
2017-11-13T09:41:27.017861Z 0 [Warning] Gtid table is not ready to be used. Table ' mysql.gtid_executed'  cannot be opened.
2017-11-13T09:41:27.022076Z 1 [Note] A temporary password is generated for root@localhost: 8oukjw%_<&OA
The above code will return the root password (8oukjw%_<&OA)for MySQL. store it for later use.
Note: if you install MySQL on a specific directory, you need to make shortcut the MySQL bin directory to /bin directory
ln -s /opt/mysql/bin/mysql /usr/local/bin

Step 8: Connect MySQL using root user and password
[centos]# cd /opt/mysql
[centos]# bin/mysql -u root -p -S /opt/mysql/mysql.sock
# once prompt an password and then re-enter new password

Step 9: Configure MySQL service daemon to auto-start on startup
[centos]# cd /opt/mysql
[centos]# cp ./support-files/mysqld_multi.server /etc/init.d/mysqld
[centos]# chmod +x /etc/init.d/mysqld
[centos]# Chkconfig -- add MySQL
[centos]# Chkconfig MySQL on 

That's pretty much it








No comments:

Post a Comment