我這里是采用純凈的系統,剛裝的centos7,而且選擇的最小安裝所以基本上是什么環境都沒有的,然后這篇文章主要針對於小白
檢查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是自動啟動的,不需要多余的配置