CentOS系統下安裝以及卸載mysql

來源:互聯網
上載者:User

標籤:

CentOS7的yum源中預設好像是沒有mysql的。為瞭解決這個問題,我們要先下載mysql的repo源。

 1. 下載mysql的repo源

[[email protected] `]$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2. 安裝mysql-community-release-el7-5.noarch.rpm包

[[email protected] `]$sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

安裝這個包後,會獲得兩個mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo.

3. 安裝mysql

[[email protected] `]sudo yum install mysql-server

根據步驟安裝就可以了,不過安裝完成後,沒有密碼,需要重設密碼。

4. 重設密碼

重設密碼前,首先要登入

[[email protected] `]mysql -u root

登入時有可能報這樣的錯:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),

原因是/var/lib/mysql的存取權限問題。下面的命令把/var/lib/mysql的擁有者改為目前使用者:

[[email protected] `]sudo chown -R root:root /var/lib/mysql

然後,重啟服務:

[[email protected] `]service mysqld restar

接下來登入重設密碼:

[[email protected] `]mysql -u root
mysql > use mysql;mysql > update user set password=password(‘123456‘) where user=‘root‘;mysql > exit;

5. 開放3306連接埠

[[email protected] `]sudo vim /etc/sysconfig/iptables

添加以下內容:

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

儲存後重啟防火牆:

[[email protected] `]sudo service iptables restart

這樣從其它客戶機也可以串連上mysql服務了。

 

CentOS 卸載mysql

yum方式安裝的mysql

[[email protected] `]yum remove mysql mysql-server mysql-libs compat-mysql51
[[email protected] `]rm -rf /var/lib/mysql

 

[[email protected] `]rm /etc/my.cnf

查看是否還有mysql軟體:

[[email protected] `]rpm -qa|grep mysql

 

如果存在的話,繼續刪除即可。

 

rpm方式安裝的mysql

1,查看系統中是否以rpm包安裝的mysql:

[[email protected] `]# rpm -qa | grep -i mysql MySQL-server-5.6.17-1.el6.i686 MySQL-client-5.6.17-1.el6.i686

2,卸載mysql

[[email protected] `]# rpm -e MySQL-server-5.6.17-1.el6.i686
[[email protected] `]# rpm -e MySQL-client-5.6.17-1.el6.i686

3,刪除mysql服務

[[email protected] `]# chkconfig --list | grep -i mysql
[[email protected] `]# chkconfig --del mysql

 

4,刪除分散mysql檔案夾

[[email protected] `]# whereis mysql 或者 find / -name mysql

5,清空相關mysql的所有目錄以及檔案(/usr/lib/mysql ,/usr/share/mysql)

[[email protected] `]rm -rf /usr/lib/mysql
[[email protected] `]rm -rf /usr/share/mysql
[[email protected] `]rm -rf /usr/my.cnf

通過以上幾步,mysql應該已經完全卸載乾淨了。

 

CentOS系統下安裝以及卸載mysql

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.