Compiling MySQL from Source

Keywords: MySQL cmake MariaDB Linux

Note: This compilation of MySQL-5.7.19 uses Linux (CentOS7) system
Yum-y install make gcc-c + + bison-devel before compilation (Ubuntu and Debian install using apt-get)

make, a very important compilation tool under Linux, the most important and basic function is to describe the relationship between source programs through makefile files and automatically maintain compilation.
gcc-c++, C++ compiler (gcc, C compiler)
bison-devel: a parser generator

Download MySQL source code
https://dev.mysql.com/downloads/mysql/

Download options:

  1. Source Code - > Source Code
  2. Generic Linux (Architecture Independent) - > Universal Linux (Independent Structure)
  3. Compressed TAR Archive, Includes Boost Headers - > Choose Compressed Packets with Boost Headers (MySQL requires Boost C++ library construction)

    wget https://dev.mysql.com/get/Dow...
    tar xzf mysql-boost-5.7.19.tar.gz
    MV mysql-5.7.19/usr/local/mysql# Move MySQL source code to / usr/local directory

To install MySQL from the source, you need to install CMake
cmake, a cross-platform compiler automatic configuration tool (to generate makefile files)

wget https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz
tar xzf cmake-3.9.0.tar.gz
cd cmake-3.9.0
./configure --prefix=/usr/local/cmack  #Fill in the installation path as needed
make && make install

If you don't want to compile and install, you can do it directly: yum-y install cmake

Start installing MySQL


cd /usr/local/mysql
#Use cmake to compile MySQL (direct cmake for yum installation does not need paths)
/usr/local/cmake/bin/cmake . -DWITH_BOOST=/usr/local/mysql/boost   #Adjust the path as needed to match your installation

Lack of ncurses-devel direct yum-y install ncurses-devel (debian/ubuntu is apt-get install libncurses 5-dev)

To prevent the use of old object files or configuration information, run the following commands in the Unix build scenario before rerunning CMake
make clean
rm -f CMakeCache.txt

Compiling MySQL with cmake again
/usr/local/cmake/bin/cmake . -DWITH_BOOST=/usr/local/mysql/boost
make

Insufficient memory, add temporary swap space under Linux (ps: because bloggers are poor, server configuration is not high; skip without this problem)
Solution: http://blog.csdn.net/razertang/article/details/45694567

make 
make install
#Create MySQL Groups and MySQL Users
groupadd mysql   
useradd -r -g mysql -s /bin/false mysql   # - s/bin/false prohibits shell use
#Change MySQL folder permissions
chown -R mysql:mysql /usr/local/mysql
#Initialize the database and generate the initial password
/usr/local/mysql/bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up

Record the initial password generated:: a0esd.M=wQF


#To prevent users from modifying MySQL files through MySQL, modify the user to root
chown -R root /usr/local/mysql/    
#Modify the data directory user generated at initialization to MySQL privileges
chown -R mysql data  
#If prompted that there is no data directory
mkdir data && chown -R mysql:mysql data

#start-up
/usr/local/mysql/bin/mysqld_safe --user=mysql &

/ var/log/mariadb/mariadb.log'does not exist

mkdir /var/log/mariadb && touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb/

Start failed, view log: cat/var/log/mariadb/mariadb.log

'/var/run/mariadb/mariadb.pid'does not exist (ps: errors are not necessarily the same, log-based problem solving)

mkdir /var/run/mariadb && touch /var/run/mariadb/mariadb.pid
chown -R mysql:mysql /var/run/mariadb/
    
# Next command is optional    
cp support-files/mysql.server /etc/init.d/mysql.server

#Log in to MySQL
/usr/local/mysql/bin/mysql -uroot -p:a0esd.M=wQF

The tmp folder lacks mysql.sock

#Soft connection mysql.sock to tmp 
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

#Log in to MySQL
/usr/local/mysql/bin/mysql -uroot -p:a0esd.M=wQF
#Modify MySQL initial password
set password = password('XXXX');

This article is based on MySQL documents.
https://dev.mysql.com/doc/refman/5.7/en/source-installation.html
https://dev.mysql.com/doc/refman/5.7/en/installing-source-distribution.html

Off-topic remarks:
In the process of compiling, you may encounter a variety of problems; but please do not go to Google to search immediately, first calm down to look at the log; believe me, you will have a harvest.

Posted by flash99 on Fri, 31 May 2019 17:32:34 -0700