Centos7下MySQL8徹底解除安裝及安裝
阿新 • • 發佈:2021-01-03
首先升級yum yum update
檢視已安裝的MySQL
[root@centos7 ~]# rpm -qa | grep -i mysql mysql80-community-release-el7-3.noarch mysql-community-client-8.0.22-1.el7.x86_64 mysql-community-common-8.0.22-1.el7.x86_64 mysql-community-server-8.0.22-1.el7.x86_64 mysql-community-client-plugins-8.0.22-1.el7.x86_64 mysql-community-libs-8.0.22-1.el7.x86_64
解除安裝
[root@centos7 ~]# yum remove -y mysql* Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. No Match for argument: mysql80-community-release-el7-3.noarch.rpm No Packages marked for removal
有可能碰到上面所示的提示,此時先解除安裝“mysql80-community-release-el7-3.noarch”
[root@centos7 ~]# yum -y remove mysql80-community-release-el7-3.noarch Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Resolving Dependencies --> Running transaction check ---> Package mysql80-community-release.noarch 0:el7-3 will be erased --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================================================================================================================================================================================ Package Arch Version Repository Size ============================================================================================================================================================================================================================================================================================================================================ Removing: mysql80-community-release noarch el7-3 installed 31 k Transaction Summary ============================================================================================================================================================================================================================================================================================================================================ Remove 1 Package Installed size: 31 k Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Erasing : mysql80-community-release-el7-3.noarch 1/1 Verifying : mysql80-community-release-el7-3.noarch 1/1 Removed: mysql80-community-release.noarch 0:el7-3 Complete!
再解除安裝其他
[root@centos7 ~]# yum -y remove mysql-*
Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-client.x86_64 0:8.0.22-1.el7 will be erased
---> Package mysql-community-client-plugins.x86_64 0:8.0.22-1.el7 will be erased
---> Package mysql-community-common.x86_64 0:8.0.22-1.el7 will be erased
---> Package mysql-community-libs.x86_64 0:8.0.22-1.el7 will be erased
---> Package mysql-community-server.x86_64 0:8.0.22-1.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
============================================================================================================================================================================================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================================================================================================================================================================================
Removing:
mysql-community-client x86_64 8.0.22-1.el7 @mysql80-community 230 M
mysql-community-client-plugins x86_64 8.0.22-1.el7 @mysql80-community 1.0 M
mysql-community-common x86_64 8.0.22-1.el7 @mysql80-community 8.9 M
mysql-community-libs x86_64 8.0.22-1.el7 @mysql80-community 22 M
mysql-community-server x86_64 8.0.22-1.el7 @mysql80-community 2.3 G
Transaction Summary
============================================================================================================================================================================================================================================================================================================================================
Remove 5 Packages
Installed size: 2.6 G
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : mysql-community-server-8.0.22-1.el7.x86_64 1/5
Erasing : mysql-community-client-8.0.22-1.el7.x86_64 2/5
Erasing : mysql-community-libs-8.0.22-1.el7.x86_64 3/5
Erasing : mysql-community-common-8.0.22-1.el7.x86_64 4/5
Erasing : mysql-community-client-plugins-8.0.22-1.el7.x86_64 5/5
Verifying : mysql-community-client-plugins-8.0.22-1.el7.x86_64 1/5
Verifying : mysql-community-common-8.0.22-1.el7.x86_64 2/5
Verifying : mysql-community-client-8.0.22-1.el7.x86_64 3/5
Verifying : mysql-community-libs-8.0.22-1.el7.x86_64 4/5
Verifying : mysql-community-server-8.0.22-1.el7.x86_64 5/5
Removed:
mysql-community-client.x86_64 0:8.0.22-1.el7 mysql-community-client-plugins.x86_64 0:8.0.22-1.el7 mysql-community-common.x86_64 0:8.0.22-1.el7 mysql-community-libs.x86_64 0:8.0.22-1.el7 mysql-community-server.x86_64 0:8.0.22-1.el7
Complete!
刪除剩餘的MySQL相關檔案和資料夾
[root@centos7 ~]# find / -name mysql
重新安裝
CentOS7好像沒有MySQL的源,取而代之是內部整合的MariaDB。官網下載MySQL的RPM源,安裝成功後會自動覆蓋MariaDB。下載完成後上傳到伺服器。
-rw-r--r-- 1 root root 26024 Jan 3 17:46 mysql80-community-release-el7-3.noarch.rpm
安裝repo並更新yum快取
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
執行後會在/etc/
下生成兩個repo檔案
[root@centos7 ~]# ll /etc/yum.repos.d/ | grep mysql
-rw-r--r-- 1 root root 2076 Apr 25 2019 mysql-community.repo
-rw-r--r-- 1 root root 2108 Apr 25 2019 mysql-community-source.repo
重新整理yum
yum clean all | yum makecache
檢視yum中的MySQL版本
[root@centos7 ~]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Comm disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Comm disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Comm disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Comm disabled
mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Comm disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Comm disabled
mysql-connectors-community/x86_64 MySQL Connectors Commu enabled: 175
mysql-connectors-community-source MySQL Connectors Commu disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 120
mysql-tools-community-source MySQL Tools Community disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - disabled
mysql55-community/x86_64 MySQL 5.5 Community Se disabled
mysql55-community-source MySQL 5.5 Community Se disabled
mysql56-community/x86_64 MySQL 5.6 Community Se disabled
mysql56-community-source MySQL 5.6 Community Se disabled
mysql57-community/x86_64 MySQL 5.7 Community Se disabled
mysql57-community-source MySQL 5.7 Community Se disabled
mysql80-community/x86_64 MySQL 8.0 Community Se enabled: 211
mysql80-community-source MySQL 8.0 Community Se disabled
MySQL8已啟用
可用命令yum-config-manager --disable mysql80-community
或yum-config-manager --enable mysql80-community
管理狀態
或直接編輯/etc/yum.repos.d/mysql-community.repo
開始安裝MySQL
yum -y install mysql-community-server
完成後開啟服務
systemctl start mysqld
設定開機自啟
systemctl enable mysqld
登入MySQL
檢視初始密碼
[root@centos7 ~]# grep 'temporary password' /var/log/mysqld.log
2021-01-03T09:56:56.709802Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Mu6Vr.s1EwsB
登入
mysql -uroot -pMu6Vr.s1EwsB
修改密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY 'custom-password!';
放行埠
使用CentOS7預設的firewall
開啟firewalld
systemctl start firewalld | systemctl enable firewalld
永久開放埠3306
firewall-cmd --permanent --zone=public --add-port=3306/tcp
重新載入使之生效
firewall-cmd --reload
檢視當前開放的埠
firewall-cmd --permanent --zone=public --list-ports
或者使用iptables
關閉firewalld服務
systemctl stop firewalld | systemctl disable firewalld | systemctl mask firewalld
沒有安裝iptables之前/etc/sysconfig/
下是沒有iptables
檔案的,所有要先安裝iptables
yum -y install iptables-services
啟動iptables服務
systemctl enable iptables | systemctl start iptables
推薦直接vim
編輯/etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3389 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 1000 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
重啟iptables
systemctl restart iptables