MySQL的编译安装,步骤详细。

实验目的:MySQL的编译安装
实验准备:
1、 1)避免端口发生冲突,先查询MySQL软件的安装情况,确认没有实验以rpm方式安装的mysql-server、mysql软件包,否则建议将其卸载。

[[email protected] httpd-2.4.25]# rpm -q mysql-server mysql
未安装软件包 mysql-server
未安装软件包 mysql

[[email protected] cmake-2.8.12]# rpm -ivh /mnt/Packages/ncurses-devel-5.9-13.20130511.el7.x86_64.rpm #安装光盘自带的ncurses-devel包(依赖包)

2) MySQL 5.X系列需要cmake编译安装,所以先行安装cmake包。

[[email protected] ~]# ls /mnt/
cmake-2.8.12.tar.gz
[[email protected] ~]# cd /mnt/
[[email protected] mnt]# tar zxf cmake-2.8.12.tar.gz -C /usr/src/
[[email protected] mnt]# cd /usr/src/cmake-2.8.12/
[[email protected] cmake-2.8.12]# ./configure
[[email protected] cmake-2.8.12]# gmake && gmake install

2、 源码编译及安装

1) 创建运行用户
[[email protected] ~]# groupadd mysql
[[email protected] ~]# useradd -M -s /sbin/nologin mysql -g mysql

2) 解包,将下载的mysql源码包解压,释放到/usr/src/下,并切换到源目录。
[[email protected] mnt]# ls
mysql-5.5.38.tar.gz
[[email protected] mnt]# tar zxf mysql-5.5.38.tar.gz -C /usr/src/
[[email protected] mnt]# cd /usr/src/mysql-5.5.38/

3) 配置
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all
安装成功的效果图

在这里插入图片描述

4) 编译并安装make && make install #安装时间较长

3、 安装后的其他调整
1) 对数据库目录进行权限设置
[[email protected] mysql-5.6.36]# chown -R mysql:mysql /usr/local/mysql/

2) 建立配置文件
[[email protected] mysql-5.6.36]# rm -rf /etc/my.cnf
[[email protected] mysql-5.6.36]# cp support-files/my-default.cnf /etc/my.cnf

3) 初始化数据库
[[email protected] mysql-5.6.36]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/

4) 设置环境变量
[[email protected] mysql-5.6.36]# echo “PATH=$PATH:/usr/local/mysql/bin”>>/etc/profile
[[email protected] mysql-5.6.36]# . /etc/profile //立即生效

4、 添加系统服务
[[email protected] mysql-5.6.36]# cp support-files/mysql.server /usr/local/mysql/bin/mysqld.sh
[[email protected] mysql-5.6.36]# chmod +x /usr/local/mysql/bin/mysqld.sh

[[email protected] mysql-5.6.36]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
After=network.target

[Service]
User=mysql
Group=mysql

Type=forking
PIDFile=/usr/local/mysql/data/localhost.localdomain.pid #主机名.pid
ExecStart=/usr/local/mysql/bin/mysqld.sh start
ExecStop=/usr/local/mysql/bin/mysqld.sh stop

[Install]
WantedBy=multi-user.target

5、 启动mysql [[email protected] mysql-5.6.36]# systemctl start mysqld