MySQL source code installation to build MySQL service

1. Preface
Building MySQL service from source code is an indispensable part of setting up an environment. Often we need to install a specified version of MySQL service in order to adapt to certain services in the environment. In this case, yum installation will be undesirable. It can be installed with source code, which is a bit more complicated, but stable and reliable

Not much nonsense, just upload the materials directly~
Second, the source code build process
1. First check whether the machine has a mysql database installed before

rpm -qa | grep -i mysql

The query under this command is installed through yum.
If you have downloaded mysql before and installed related services, execute the following command to uninstall
2. Uninstall the mysql database in the system (stop the mysql database before uninstalling)

#停掉服务
/etc/init.d/mysqld stop
#查询是否已经停止
/etc/init.d/mysqld status
#然后卸载mysql数据库
#使用rpm -ev进行卸载组件会提示先卸载依赖包,所以需要在加多 --nodeps忽略依赖包进行卸载。
rpm -ev mysql-server....【通过rpm查询出来的服务】 --nodeps

3. Then check if there are residual mysql directories or files

whereis mysql
find / -name mysql

4. Yum installs the tools and libraries needed for compilation [Generally, these are necessary for normal online environment, if not, execute the command to install]

yum install -y gcc gcc-c++ ncurses-devel perl

After the installation is complete, you can check with rpm -qa | xxx
5. Before compiling and installing mysql, create the mysql user and group, as well as the mysql installation directory and the data storage directory

sudo groupadd mysql
sudo useradd -g mysql mysql
mkdir -p /usr/local/mysql  # 创建mysql安装目录
mkdir -p /usr/local/mysql/data    # 创建mysql数据库存放目录
sudo chown -R mysql.mysql /usr/local/mysql      #设置mysql目录权限

mysql source code installation package download address:
official website download address: https://dev.mysql.com/downloads/mysql/
other download addresses: http://mirrors.sohu.com/mysql/

6. Upload the downloaded installation package to the Centos system and unzip it

tar -xvf mysql-5.5.32-linux2.6-x86_64.tar.gz 

7. Then compile and install

cd mysql-5.5.32
./configure --prefix=/usr/local/mysql --libexecdir=/usr/sbin --localstatedir=/usr/local/mysql/data --sysconfdir=/etc/my.cnf 
make && make install

Note: –prefix: indicates the installation root directory
–libexecdir=/usr/sbin: indicates the mysqld directory
–localstatedir=/usr/local/mysql/data: mysql data storage directory
–sysconfdir=/etc/my.cnf: mysql configuration file
8 , And then edit the mysql configuration file

vim /etc/my.cnf
Insert picture description here


9. Then initialize the mysql system database

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql    		         //利用mysql的身份去安装mysql数据库并初始化数据库	
Insert picture description here


10. Then copy the startup script of the mysqld service to the /etc/init.d directory

cp support-files/mysql.server /etc/init.d/mysqld   // 将mysqld服务的启动脚本复制到/etc/init.d目录下
chmod +x /etc/init.d/mysqld     // 为目录添加执行权限
/etc/init.d/mysqld start             // 启动mysqld的服务
/etc/init.d/mysqld status          // 查看mysqld服务的状态
Insert picture description here


10. You can check whether the process is started through ps -ef | grep mysqld

Insert picture description here


11. Then start the mysqld service

./mysql -u root -p
Insert picture description here


OK~
Build is complete