下載好安裝包: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