版本:linux7.6
一.编译安装
1.下载epel源
[root@db01 ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
2.安装依赖
[root@db01 ~]# yum install -y ncurses-devel libaio-devel autoconf cmake gcc gcc-c++ glibc
3.解压MySQL源码包
[root@db01 ~]# tar xf mysql-5.6.40.tar.gz
4.进去源码包目录
[root@db01 ~]# cd mysql-5.6.40/
5.创建目录
[root@db01 ~]# mkdir /application
6.生成编译文件
[root@db01 mysql-5.6.40]# cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.40 #程序存放位置 -DMYSQL_DATADIR=/application/mysql-5.6.40/data \ #数据存放位置-DMYSQL_UNIX_ADDR=/application/mysql-5.6.40/tmp/mysql.sock #使用utf8字符集-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 \ #启用zlib库支持(zib、gzib相关)-DWITH_SSL=bundled \ #启用SSL库支持(安全套接层)-DENABLED_LOCAL_INFILE=1 \ #启用本地数据导入支持-DWITH_EMBEDDED_SERVER=1 \ #编译嵌入式服务器支持-DENABLE_DOWNLOADS=1 \ # mysql5.6支持了google的c++mock框架了,允许下载,否则会安装报错。-DWITH_DEBUG=0 #禁用debug(默认为禁用)
7.编译安装
[root@db01 mysql-5.6.40]# make && make install
8.创建MySQL用户
[root@db01 mysql-5.6.40]# useradd mysql -s /sbin/nologin -M
9.做软链接
[root@db01 mysql-5.6.40]# ln -s /application/mysql-5.6.40 /application/mysql
10.进去其他文件目录
[root@db01 mysql-5.6.40]# cd /application/mysql/support-files
11.拷贝MySQL配置文件
[root@db01 support-files]# cp my-default.cnf /etc/my.cnfcp: overwrite ‘/etc/my.cnf’? y
12.拷贝启动脚本
[root@db01 support-files]# cp mysql.server /etc/init.d/mysqld
13.进去初始化目录
[root@db01 support-files]# cd /application/mysql/scripts
14.初始化MySQL
[root@db01 scripts]# ./mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
15.创建socket文件所在目录
[root@db01 scripts]# mkdir /application/mysql-5.6.40/tmp
16.授权MySQL服务目录
[root@db01 scripts]# chown -R mysql.mysql /application/mysql*
17.添加环境变量
[root@db01 scripts]# vim /etc/profile.d/mysql.shexport PATH="/application/mysql/bin:$PATH"
18.加载环境变量
[root@db01 scripts]# source /etc/profile
19.启动MySQL
[root@db01 scripts]# /etc/init.d/mysqld start
20用systemctl管理
[root@db01 ~]# vim /usr/lib/systemd/system/mysqld.service[Unit]Description=MySQL ServerDocumentation=man:mysqld(8)Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.htmlAfter=network.targetAfter=syslog.target[Install]WantedBy=multi-user.target[Service]User=mysqlGroup=mysqlExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnfLimitNOFILE = 5000[root@db01 ~]# /etc/init.d/mysqld stopShutting down MySQL.. SUCCESS![root@db01 ~]# systemctl start mysqld
二.二进制安装
1.解压二进制包
[root@db02 ~]# tar xf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
2.创建MySQL安装目录
[root@db02 ~]# mkdir /application
3.启动MySQL程序到安装目录下
[root@db02 ~]# mv mysql-5.6.40-linux-glibc2.12-x86_64 /application/mysql-5.6.40
4.做软链接
[root@db02 ~]# ln -s /application/mysql-5.6.40 /application/mysql
5. 进入其他文件目录
[root@db02 ~]# cd /application/mysql/support-files
6.拷贝配置文件
[root@db02 support-files]# cp my-default.cnf /etc/my.cnfcp: overwrite ‘/etc/my.cnf’? y
7. 拷贝启动脚本
[root@db02 support-files]# cp mysql.server /etc/init.d/mysqld
8.进入初始化目录
[root@db02 support-files]# cd ../scripts/
9.创建MySQL用户
[root@db02 scripts]# useradd mysql -s /sbin/nologin -M
10.安装初始化依赖
[root@db02 scripts]# yum install -y autoconf libaio-devel
11.初始化
[root@db02 scripts]# ./mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
12.启动mysq
[root@db02 scripts]# /etc/init.d/mysqld start
13.添加环境变量
[root@db02 scripts]# vim /etc/profile.d/mysql.shexport PATH="/application/mysql/bin:$PATH"
14.修改
[root@db02 scripts]# sed -i ‘s#/usr/local#/application#g‘ /etc/init.d/mysqld /application/mysql/bin/mysqld_safe
15.用systemctl管理.在/etc/my.cnf添加两行信息
[root@db02 mysql]# cat /etc/my.cnfbasedir = /application/mysqldatadir = /application/mysql/data
16.启动加入开机自启动
[root@db02 mysql]# /etc/init.d/mysqld stop[root@db02 mysql]# /etc/init.d/mysqld start [root@db02 mysql]# systemctl start mysqld[root@db02 mysql]# systemctl enable mysqld