1 查看是否已經(jīng)安裝了mariadb
- 檢查命令:yum list installed | grep mariadb
- 卸載命令:yum remove 【mariadb】
2 對(duì)應(yīng)系統(tǒng)版本MySQL安裝包在MySQL官方網(wǎng)站下載,通過XFTP等ftp軟件上傳到服務(wù)器【/opt/tar/】文件夾下环戈,解壓到【/opt/tool/】文件夾下
3 解壓安裝包
- 方式一 命令:tar -xf mysql-8.0.37-linux-glibc2.17-x86_64.tar.xz -C /opt/tool/
方式二 命令:tar -Jxvf mysql-8.0.37-linux-glibc2.17-x86_64.tar.xz -C /opt/tool/
使用mv命令修改解壓后的文件名
3 安裝依賴包
命令:yum install libaio
4 配置MySQL
4.1 為MySQL創(chuàng)建專用的用戶和組,以確保數(shù)據(jù)庫的安全運(yùn)行诸狭。
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
## 4.2 將MySQL安裝目錄及其子目錄的所有者和組更改為mysql用戶和組炸宵。
```bash
chown -R mysql:mysql /opt/tool/mysql-8.0.37/
# 修改MySQL安裝目錄訪問權(quán)限可選權(quán)限(可能需要)
[root@hcss-ecs-7570 tool]# ll
total 12
drwxr-xr-x 9 root root 4096 Jul 1 19:42 apache-tomcat-10.1.25
drwxr-xr-x 9 root root 4096 Jul 1 19:42 jdk17
drwxr-xr-x 10 mysql mysql 4096 Jul 3 23:46 mysql-8.0.37
[root@hcss-ecs-7570 tool]# chmod 777 mysql-8.0.37/
[root@hcss-ecs-7570 tool]# ll
total 12
drwxr-xr-x 9 root root 4096 Jul 1 19:42 apache-tomcat-10.1.25
drwxr-xr-x 9 root root 4096 Jul 1 19:42 jdk17
drwxrwxrwx 10 mysql mysql 4096 Jul 3 23:46 mysql-8.0.37
[root@hcss-ecs-7570 tool]#
chmod 777
## 4.3 在MySQL安裝目錄下創(chuàng)建用于存放數(shù)據(jù)庫文件的目錄辟躏。
```bash
mkdir /opt/tool/mysql-8.0.37/data
4.4 初始化MySQL
切換到MySQL的bin目錄下,執(zhí)行初始化命令土全。
[root@hcss-ecs-7570 bin]# ./mysqld --initialize --user=mysql --basedir=/opt/tool/mysql-8.0.37/ --datadir=/opt/tool/mysql-8.0.37/data/
2024-07-03T16:05:07.702925Z 0 [System] [MY-013169] [Server] /opt/tool/mysql-8.0.37/bin/mysqld (mysqld 8.0.37) initializing of server in progress as process 17985
2024-07-03T16:05:07.733974Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-07-03T16:05:08.262330Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-07-03T16:05:10.120610Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: n!dRxXqIN4Gf
4.5 啟動(dòng)MySQL
./mysqld_safe
4.6 修改root登陸密碼
alter user 'root'@'localhost' identified by 'root';
5 遠(yuǎn)程登陸設(shè)置
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
FLUSH PRIVILEGES;
* 刪除命令
rm -rf 【需要?jiǎng)h除的文件名\包含路徑的文件名】