1、查看是否安裝歷史版本
# 查看
rpm -qa|grep mysql
rpm -qa|grep mariadb
# 卸載
yum -y remove #mysql安裝包名稱
yum -y remove #mariadb安裝包名稱
2、下載安裝
[root@localhost ~]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
[root@localhost ~]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
[root@localhost ~]# yum install -y mysql mysql-server
[root@localhost ~]# mysql -V //查看當(dāng)前安裝mysql版本
mysql Ver 14.14 Distrib 5.7.27, for Linux (x86_64) using EditLine wrapper
3、修改密碼
[root@localhost ~]# systemctl start mysqld //啟動mysql服務(wù)
[root@localhost ~]# grep "password" /var/log/mysqld.log //通過log查看初始密碼
2021-08-05T16:17:00.010786Z 1 [Note] A temporary password is generated for root@localhost: i0d?ur_#rr+O0 //i0d?ur_#rr+O0此為mysql初始密碼
[root@localhost ~]# mysql -u root -p
Enter password: //輸入初始密碼i8d?ur_#rr+O
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'localhost' identified by 'Password'; //重置mysql密碼為:Password
Query OK, 0 rows affected (0.00 sec)
mysql> update mysql.user set host='%' where host='localhost'; //root用戶可使用任意IP登錄數(shù)據(jù)庫
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> flush privileges; //刷新權(quán)限
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。