1,在mysql官网,如下地址,下载安装包,最后那个tar包解压后,有三个包,其中一个是上面红笔画的那个包,所以可以直接下载上面那个包。
https://dev.mysql.com/downloads/mysql/
2. 通过rz工具上传到Linux系统中,解压并放到指定目录/usr/local/mysql
mv mysql-8.0.18-linux-x86_64-minimal /usr/local/mysql
3. 创建用户mysql, 创建数据文件存放目录及添加权限
useradd -s /sbin/nologin mysql
mkdir -p /data/mysql/data
chown -R mysql:mysql /data/mysql
cd usr/local/mysql/
chown -R mysql:mysql ./
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
注意root@localhost后的密码
4. 制作配置文件,创建文件 my.cnf 及文件夹/etc/my.cnf.d
mkdir /etc/my.cnf.d //mysql服务停止时,要用该文件夹
vi /etc/my.cnf, 粘入以下内容
[client]
port=3306 # 设置mysql客户端连接服务端时默认使用的端口
default-character-set=utf8
socket=/data/mysql/data/mysql.sock
[mysqld]
basedir=/usr/local/mysql # 设置mysql的安装目录
datadir=/data/mysql/data
socket=/data/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/data/log/mysql-log/error.log
pid-file=/data/mysql/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
5. 制作启动脚本
cp support-files/mysql.server /etc/init.d/mysqld
chomd 755 /etc/init.d/mysqld
这里需要更新如下内容
如果通过如下命令启动MYSQL, mysql.server文件也需要更新如上内容
/usr/local/mysql/support-files/mysql.server start
另外,注意mysqld_pid_file_path这个不要写路径,写了启动查看状态会错,
6. 设定开机启动并启动MYSQL
chkconfig --add mysqld
chkconfig mysqld on
service mysqld start
如果启动不了,检查/data/mysql/目录下的错误日志,检查MYSQL是否启动
ps aux | grep mysqld