Linux/CentOS下開啟MySQL遠端連線,遠端管理資料庫

來源:互聯網
上載者:User

標籤:

當伺服器沒有運行PHP、沒裝phpMyAdmin的時候,遠端管理MySQL就顯得有必要了。

第一步:開啟MySQL使用者的遠端存取許可權

mysql -u root -p mysql # 第1個mysql是執行命令,第2個mysql是系統資料名稱

在MySQL控制台執行:

grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘ with grant option;# root是使用者名稱,%代表任意主機,‘123456‘指定的登入密碼(這個和本地的root密碼可以設定不同的,互不影響)flush privileges; # 重載系統許可權exit;

如果想允許使用者root從ip為192.168.137.99的主機串連到MySQL服務:

grant all privileges on *.* to ‘root‘@‘192.168.137.99‘ identified by ‘123456‘ with grant option;flush privileges;

 

第二步:設定防火牆,讓 3306 連接埠對外可訪問

iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT# 查看規則是否生效iptables -L -n # 或者: service iptables status# 此時生產環境是不安全的,遠端管理之後應該關閉連接埠,刪除之前添加的規則iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

注意:上面iptables添加/刪除規則都是臨時的,如果需要重啟後也生效,需要儲存修改:

service iptables save # 或者: /etc/init.d/iptables save

另外,

vi /etc/sysconfig/iptables # 加上下面這行規則也是可以的-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

遠端管理資料庫的軟體,win系統下可以使用SQLyog(),用了幾種遠程軟體,感覺這個用起來蠻不錯的。

 

 

 

 

【附加說明】若安裝了phpMyAdmin,也可按如下方式修改使用者權限:

Linux/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.