首先官網下載rpm包,這裏我選擇了bundle包,裏面有各類MySQL的依賴mysql
下載完畢後,能夠本身在centos上建立一個mysql文件夾,而後將該文件上傳到該文件夾,而後解壓sql
tar -xvf mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar centos
解壓以後以下圖ide
能夠看到不少的rpm文件,咱們須要安裝的主要是client和server3d
首先安裝client,安裝client以前須要先安裝兩個依賴rpm,若是你安裝錯了,能夠用下面的命令清除以前安裝過的依賴rest
yum remove mysql-libsserver
安裝依賴mysql-community-common-8.0.19-1.el7.x86_64.rpmblog
rpm -ivh mysql-community-common-8.0.19-1.el7.x86_64.rpmrem
安裝依賴mysql-community-libs-8.0.19-1.el7.x86_64.rpm文件上傳
rpm -ivh mysql-community-libs-8.0.19-1.el7.x86_64.rpm
安裝客戶端mysql-community-client-8.0.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.19-1.el7.x86_64.rpm
安裝依賴libaio
yum install libaio
安裝服務端mysql-community-server-8.0.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.19-1.el7.x86_64.rpm
查看是否安裝成功
ps -ef | grep mysql
接下來進行對MySQL的初始化
mysqld --initialize
啓動MySQL服務
systemctl start mysqld
啓動失敗,由於權限的問題,下面修改權限
chown -R mysql:mysql /var/lib/mysql/
再次啓動服務
systemctl start mysqld
查看初始化密碼
cat /var/log/mysqld.log | grep password
登陸MySQL,密碼是上面那個
mysql -u root -p
修改登陸密碼
alter user 'root'@'localhost' identified by 'root';
中止服務、重啓服務
systemctl stop mysqldsystemctl restart mysqld