1,使用rpm -qa | grep mysql命令,檢查系統是否已經安裝了mysql,如果已經安裝mysql,需要先卸載。
2,添加在線mysql源
vim /etc/yum.repos.d/mysql.repo
將下面的內容添加到mysql源
# Enable to use MySQL 8.0
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/8/x86_64/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

3,安裝mysql
yum module disable mysql
yum update
yum install -y mysql-community-common mysql-community-libs mysql-community-client mysql-community-server mysql-community-devel

4,啟動mysql服務 (停止mysql服務的命令是:systemctl stop mysqld.service)
systemctl start mysqld.service
![]()
5,查看mysql狀態
systemctl status mysqld.service

6,將mysql設置為開機自啟
systemctl enable mysqld.service

7,登錄mysql的時候需要設置密碼:首先生成隨機密碼
grep 'temporary password' /var/log/mysqld.log
![]()
8,登錄mysql
mysql -uroot -p
然后輸入剛才收成的隨機密碼

9,接下來我們要修改一下密碼
alter user 'root'@'localhost' identified by 'abc@123456';
重新登錄

mysql就安裝完成了
