二进制安装指定目录下
0.安装依赖
1.解压二进制安装包
2.创建自定义目录
3.移动目录并做软链接
4.创建用户
5.拷贝配置文件和启动脚本
6.初始化数据库
7.启动数据库
8.做软链接或者把命令加入环境变量
9.编辑启动脚本
10.使用systemctl管理
1.安装依赖
[root@db03 ~]# yum install -y ncurses-devel libaio-devel gcc gcc-c++ glibc cmake autoconf openssl openssl-devel
2.解压
rz
[root@db03 ~]# tar xf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
3.创建自定义目录
[root@db03 ~]# mkdir /service
4.移动目录并做软链接
[root@db03 ~]# mv mysql-5.6.46-linux-glibc2.12-x86_64 /service/
[root@db03 ~]# ln -s /service/mysql-5.6.46-linux-glibc2.12-x86_64 /service/mysql
5.创建用户
[root@db03 ~]# useradd mysql -s /sbin/nologin -M
6.拷贝配置文件和启动脚本
[root@db03 ~]# cp /service/mysql/support-files/my-default.cnf /etc/my.cnf
cp: overwrite '/etc/my.cnf'? y
[root@db03 ~]# cp /service/mysql/support-files/mysql.server /etc/init.d/mysqld
---------------------------------------------
7.初始化数据库
[root@db03 ~]# cd /service/mysql/scripts/
[root@db03 scripts]# ./mysql_install_db --user=mysql --basedir=/service/mysql --datadir=/service/mysql/data
8.配置system管理mysql
[root@db03 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@db03 scripts]# systemctl daemon-reload
[root@db03 scripts]# systemctl start mysqld
[root@db03 scripts]# ps -ef|grep mysql
[root@db03 scripts]# netstat -lntup|grep 3306
#启动数据库
1.
[root@m01 scripts]# /etc/init.d/mysqld start
#启动失败,因为mysql文件中很多都是/usr/local/mysql,我们需要替换
[root@db03 mysql]# sed -i 's#/usr/local/mysql#/service/mysql#g' /etc/init.d/mysqld /service/mysql/bin/mysqld_safe
2.
#修改配置文件
[root@db03 mysql]# vim /etc/my.cnf
basedir = /service/mysql
datadir = /service/mysql/data
#再次启动
[root@db03 mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/service/mysql/data/db03.err'.
SUCCESS!
1.配置环境变量
[root@db03 scripts]# vim /etc/profile.d/mysql.sh
export PATH=/service/mysql/bin:$PATH
[root@db03 mysql]# source /etc/profile
2.检测进程和端口
[root@m01 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@m01 scripts]# netstat -lntp
tcp6 0 0 :::3306 :::* LISTEN 12886/mysqld