centos7 國內鏡像yum安裝mysql5.7

檢查mysql環境是否已存在

雖然我的是純淨系統,但別人的不能保證,爲了避免發生什麼問題我們還是先檢查下mysql是否已經安裝過

[root@localhost ~]#  rpm -qa | grep mysql
[root@localhost ~]# rpm -qa |grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64

我這裏要卸載mariadb

[root@localhost ~]# yum remove mariadb-libs-5.5.64-1.el7.x86_64

假如你發現類似的就和我一樣刪除就好了

切換阿里雲鏡像源

先安裝wget

[root@localhost ~]# yum install wget -y

然後下載阿里雲yum源配置

[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

然後生成緩存

[root@localhost ~]# yum makecache

顯視元數據緩存已建立就代表完成了

然後我們更新一下yum

[root@localhost ~]# yum update -y

這可能需要一點時間,耐心等待一下

下載國內的mysql rpm包並安裝

地址爲http://mirrors.ustc.edu.cn/mysql-ftp/Downloads
我這裏直接通過下載地址下載

先是server包

[root@localhost ~]# wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-server-5.7.25-1.el7.x86_64.rpm

然後是client包

wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-client-5.7.25-1.el7.x86_64.rpm

還有common

[root@localhost ~]# wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-common-5.7.25-1.el7.x86_64.rpm

最後還有一個lib

[root@localhost ~]# wget http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-community-libs-5.7.25-1.el7.x86_64.rpm

在此之前我們還要先安裝三個依賴環境
net-tools.x86_64,libaio.x86_64,perl.x86_64

我們直接使用yum安裝

yum install -y perl.x86_64
yum install -y libaio.x86_64
yum install -y net-tools.x86_64

然後按照順序安裝mysql的依賴

[root@localhost ~]# rpm -ivh mysql-community-common-5.7.25-1.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh mysql-community-client-5.7.25-1.el7.x86_64.rpm
[root@localhost ~]# rpm -ivh mysql-community-server-5.7.25-1.el7.x86_64.rpm

然後我們重啓下mysql服務

[root@localhost ~]# service mysqld.service restart

我們查看下默認密碼

[root@localhost etc]# grep 'temporary password' /var/log/mysqld.log
2020-02-11T09:49:32.224110Z 1 [Note] A temporary password is generated for root@localhost: E;#ySHlql0!>

我的密碼爲 E;#ySHlql0!>

[root@localhost mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.25

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> 

登錄成功,接着改下密碼和遠程連接

修改密碼並開啓遠程連接

修改密碼

這裏因爲mysql的新版本限制了密碼複雜度,所以我們需要設置一個稍微複雜的密碼

mysql>  set password=password('這裏輸入你想改的密碼');
Query OK, 0 rows affected, 1 warning (0.00 sec)

密碼需要包含數字和特殊符號,以及大寫字母和小寫字母
當然你設置完成以後可以就將密碼限制關閉後在重新改密碼,這裏不過多演示

開啓遠程連接

打開mysql數據庫

mysql> use mysql;

修改一條數據使其支持遠程連接

mysql> update user set Host = '%' where Host = 'localhost' and User='root';

刷新系統權限相關表

mysql> flush privileges;

我們用navicat測一下
在此之前請確保防火牆開放了3306端口

技術圖片
我這裏直接一次過了

關於開機自啓,這種情況下mysql是自動啓動的,不需要多餘的配置

centos7 國內鏡像yum安裝mysql5.7

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章