CentOS7安裝MySQL並開啟遠端存取

來源:互聯網
上載者:User

標籤:

1.安裝MySQL

CentOS7中預設安裝了MySQL系列的資料庫,需要先卸載掉。

查看當前安裝的mariadb包:

[[email protected] desktop]# rpm -qa | grep mariadb

將它們統統強制性卸載掉:

[[email protected] 案頭]# rpm -e --nodeps mariadb-libs-5.5.35-3.el7.x86_64

在官網下載RPM安裝包,http://dev.mysql.com/downloads/mysql/,下載完成後解壓。

雙擊安裝MySQL-server,MySQL-client和MySQL-devel三個安裝包。

 

2. 啟動MYSQL

[[email protected] desktop]#service mysql start

得到錯誤:ERROR!The server quit without updating PID file

我們這裡主要是因為:selinux惹的禍,如果是centos系統,預設會開啟selinux。解決方案是關閉它,開啟/etc/selinux/config,把SELINUX=enforcing改為SELINUX=disabled後存檔退出重啟機器。

然後再啟動mysql就沒問題了:

[[email protected] desktop]#service mysql start

查看MySQL運行狀態:

[[email protected] desktop]# service mysql status

SUCCESS! MySQL running (2377)

 

3. 設定密碼

安裝之後root使用者預設沒有密碼,通過命令設定密碼。

[[email protected] desktop]# /usr/bin/mysqladmin -u root password ‘passok‘

然後設定root使用者的遠端存取許可權

在mysql控制台執行

GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘MyPassword‘ WITH GRANT OPTION;

FLUSH PRIVILEGES; 

 

4.開啟遠端連線

需要安裝iptables,

yum install -y iptables

然後編輯系統的開放連接埠列表,增加3306連接埠,重啟防火牆即可。

CentOS7安裝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.