CentOS7.5编译安装MySQL-5.6.40

1.安装依赖包

[root@db01 ~]# yum install -y gcc gcc-c++ automake autoconf cmake bison-devel ncurses-devel libaio-devel

2.下载MySQL-5.6.40.tar.gz

[root@db01 ~]# wget https://downloads.mysql.com/archives/get/file/mysql-5.6.40.tar.gz

3.解压缩

[root@db01 ~]# tar xf mysql-5.6.40.tar.gz

4.进入解压缩目录,进行编译安装

//进入到解压目录
[root@db01 ~]# cd mysql-5.6.40

//进行cmake
[root@db01 mysql-5.6.40]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.40 \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_EXTRA_CHARSETS=all \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_FEDERATED_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
> -DWITH_ZLIB=bundled \
> -DWITH_SSL=bundled \
> -DENABLED_LOCAL_INFILE=1 \
> -DWITH_EMBEDDED_SERVER=1 \
> -DENABLE_DOWNLOADS=1 \
> -DWITH_DEBUG=0

//编译并安装
[root@db01 mysql-5.6.40]# make && make install

5.创建mysql用户和组并做mysql安装目录软连接

//创建mysql组
[root@db01 ~]# groupadd mysql

//创建mysql用户
[root@db01 ~]# useradd -r -g mysql -s /bin/false mysql

//修改mysql目录权限
[root@db01 ~]# chown -R mysql.mysql /usr/local/mysql-5.6.40

//做mysql安装目录软连接
[root@db01 ~]# ln -s /usr/local/mysql-5.6.40  /usr/local/mysql

6.初始化数据库

[root@db01 ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

7.拷贝mysql主配置文件

//备份/etc/my.cnf
[root@db01 ~]# mv /etc/my.cnf /etc/my.cnf.old

//拷贝mysql配置文件
[root@db01 ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

8.拷贝mysql启动文件

[root@db01 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

9.导出mysql命令环境变量

//最好不要直接追加到/etc/profile,可选择在/etc/profile.d/创建一个x.sh
[root@db01 ~]# echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh

//使配置生效
[root@db01 ~]# source /etc/profile

10.启动mysql

[root@db01 ~]# /etc/init.d/mysqld start

11.用systemd管理mysql

//编辑/usr/lib/systemd/system/mysqld.service,写入以下几行
[root@db01 ~]# cat > /usr/lib/systemd/system/mysqld.service <<EOF
#
# Simple MySQL systemd service file
#
# systemd supports lots of fancy features, look here (and linked docs) for a full list: 
#  http://www.freedesktop.org/software/systemd/man/systemd.exec.html
#
# Note: this file ( /usr/lib/systemd/system/mysql.service )
# will be overwritten on package upgrade, please copy the file to 
#
#  /etc/systemd/system/mysql.service 
#  
# to make needed changes.
# 
# systemd-delta can be used to check differences between the two mysql.service files.
#

[Unit]
Description=MySQL Community Server
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target
Alias=mysql.service

[Service]
User=mysql
Group=mysql

# Execute pre and post scripts as root
PermissionsStartOnly=true

# Needed to create system tables etc.
#ExecStartPre=/usr/bin/mysql-systemd-start pre

# Start main service
ExecStart=/usr/local/mysql/bin/mysqld_safe

# Don't signal startup success before a ping works
#ExecStartPost=/usr/bin/mysql-systemd-start post

# Give up if ping don't get an answer
TimeoutSec=600

Restart=always
PrivateTmp=false
EOF

到此,mysql5.6.40编译安装完成!!!


扩展:一台主机mysql已经编译好,通过拷贝相关目录和文件的方式快速部署其他mysql实例

步骤:

  • 1.几台机器的环境要一致,操作系统、硬件环境

  • 2.拷贝mysql编译安装路径目录,本文为/usr/local/mysql-5.6.40

  • 3.拷贝mysql配置文件、启动文件、mysql命令环境变量文件/etc/profile(或者在另外的mysql主机手动填写)

  • 4.拷贝systemd管理文件

  • 5.创建mysql用户和组

1.已经编译安装好的mysql主机拷贝相关包

//打包mysql编译安装目录
[root@db01 ~]# cd /usr/local
[root@db01 local]# tar cf /root/mysql.tar mysql-5.6.40

//将包拷贝至另一台mysql主机
[root@db01 ~]# scp mysql.tar 10.0.0.3:/usr/local

//拷贝配置文件
[root@db01 ~]# scp /usr/local/mysql-5.6.40/support-files/my-default.cnf 10.0.0.3:/etc

//拷贝启动文件
[root@db01 ~]# scp /etc/init.d/mysqld 10.0.0.3:/etc/init.d

//拷贝systemd管理文件
[root@db01 ~]# scp /usr/lib/systemd/system/mysqld.service 10.0.0.3:/usr/lib/systemd/system

//拷贝mysql命令环境变量文件
[root@db01 local]# scp /etc/profile.d/mysql.sh 10.0.0.3:/etc/profile.d

2.另外一台mysql主机操作

/创建mysql用户和组
[root@db03 ~]# groupadd mysql
[root@db03 ~]# useradd -r -g mysql -s /bin/false mysql

//解压缩拷贝过来的mysql包
[root@db03 ~]# cd /usr/local
[root@db03 local]# tar xf mysql.tar

//修改mysql所有者
[root@db03 local]# chown -R mysql.mysql mysql-5.6.40

//做软连接
[root@db03 local]# ln -s mysql-5.6.40/ mysql

//使mysql命令环境变量配置生效
[root@db03 local]# source /etc/profile

//备份/etc/my.cnf
[root@db03 local]# mv my.cnf my.cnf.old

//修改拷贝过来的mysql配置文件
[root@db03 local]# mv my-default.cnf my.cnf

//启动mysql并设置开机自启
[root@db03 ~]# systemctl start mysqld ; systemctl enable mysqld
或者
[root@db03 ~]# /etc/init.d/mysqld start

//验证端口
[root@db03 ~]# netstat -ntpl|grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      1799/mysqld

到此,快速部署mysql完成

泡泡吐肥皂o © gitbook.pptfz.top 2021 all right reserved,powered by Gitbook文件修订时间: 秃笔南波湾!!!

results matching ""

    No results matching ""