CentOS7 安装 mysql-8.0.25-el7-x86_64.tar.gz
下载好安装包:mysql-8.0.25-el7-x86_64.tar.gz
假设解压后的目录为: /opt/mysql/mysql-8.0.25-el7-x86_64
1、修改脚本
进入该目录下的脚本文件: support-files/mysql.server
根据脚本内容,假设设置变量为:
basedir=/opt/mysql/mysql-8.0.25-el7-x86_64 datadir=/opt/mysql/data
basedir 表示mysql安装包家目录;
datadir 表示存放数据文件的目录;
2、编辑配置文件 /etc/my.cnf
[mysqld] datadir=/opt/mysql/data # socket=/opt/mysql/mysql-8.0.25-el7-x86_64/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=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
# include all files from the config directory
!includedir /etc/my.cnf.d
确保 datadir 跟步骤1 一致;
3. 创建mysql 组及用户
groupadd mysql useradd -r -g mysql -s /bin/false mysql
4. 设置用户 mysql 拥有mysql数据目录及mysql家目录权限
chown -R mysql:mysql /opt/mysql/data chown -R mysql:mysql /opt/mysql/mysql-8.0.25-el7-x86_64
5. 生成mysql数据文件
在 /opt/mysql/mysql-8.0.25-el7-x86_64 目录里,运行:
./bin/mysqld --user=mysql --base=/opt/mysql/mysql-8.0.25-el7-x86_64 --datadir=/opt/mysql/data --initialize
6、启动mysql服务
在 /opt/mysql/mysql-8.0.25-el7-x86_64 目录里,运行:
./support-files/mysql.server start