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