安装依赖
[root@m01 ~]# yum install -y ncurses-devel libaio-devel gcc gcc-c++ glibc cmake autoconf openssl openssl-devel
创建目录并进入
[root@db01 ~]# mkdir /service
[root@db01 ~]# cd /service
上传解压包并解压
[root@db01 service]# rz
[root@db01 service]# tar xf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
[root@db01 service]# ll
total 0
drwxr-xr-x 13 root root 223 Jul 30 21:35 mysql-5.6.46-linux-glibc2.12-x86_64
做软连接
[root@db01 service]# ln -s /service/mysql-5.6.46-linux-glibc2.12-x86_64 /service/mysql
创建用户
[root@db01 service]# useradd mysql -s /sbin/nologin -M
拷贝配置文件和启动脚本
[root@db01 ~]# cd /service/mysql/support-files/
[root@db01 support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite '/etc/my.cnf'? y
[root@db01 support-files]# cp mysql.server /etc/init.d/mysqld
初始化数据库
[root@db01 ~]# cd /service/mysql/scripts/
[root@db01 scripts]# ./mysql_install_db --user=mysql --basedir=/service/mysql --datadir=/service/mysql/data(标志为两个OK)
配置system管理mysql
[root@db01 scripts]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/service/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
[root@db01 scripts]# systemctl daemon-reload
[root@db01 scripts]# systemctl start mysqld
启动数据库
[root@db01 scripts]# /etc/init.d/mysqld start
#启动失败,因为mysql文件中很多都是/usr/local/mysql,我们需要替换
[root@db01 mysql]# sed -i 's#/usr/local/mysql#/service/mysql#g' /etc/init.d/mysqld /service/mysql/bin/mysqld_safe
#修改配置文件
[root@db01 mysql]# vim /etc/my.cnf
basedir = /service/mysql
datadir = /service/mysql/data
#再次启动
[root@db01 mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/service/mysql/data/db03.err'.
SUCCESS!
配置环境变量
[root@db01 scripts]# vim /etc/profile.d/mysql.sh
export PATH=/service/mysql/bin:$PATH
[root@db01 mysql]# source /etc/profile
确认启动
[root@db01 scripts]# ps -ef | grep mysql
mysql 12886 1 2 03:10 ? 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
root 12921 10636 0 03:11 pts/1 00:00:00 grep --color=auto mysql
[root@db01 scripts]# netstat -lntp
tcp6 0 0 :::3306 :::* LISTEN 12886/mysqld
