Linux中開啟MySQL遠端存取功能

來源:互聯網
上載者:User

(1)確認一下3306是否對外開放,MySQL預設狀態下是不開放對外訪問功能的。查看的辦法如下:

1 ~# netstat -an | grep 3306 

2 tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN

從上面可以看出,mysql的3306連接埠只是監聽本地的串連,這樣就阻礙了外部IP對該資料庫的訪問,修改的辦法其實很簡單,進入到mysql的設定檔所在目錄(/etc/mysql/my.cnf)下,找到檔案中的如下內容:


1 # Instead of skip-networking the default is now to listen only on 

2 # localhost which is more compatible and is not less secure. 

3 bind-address = 127.0.0.1

給bind-address添加註釋,(或者改成你想要使用的用戶端主機IP)(這個我沒成功)。
這樣mysql的遠端存取連接埠就算開啟了,下面還有一個更重要的步驟,就是要給遠端使用者授權。

(2)確認用戶端使用者是否具有存取權限。
為了讓訪問mysql的用戶端的使用者有存取權限,我們可以通過如下方式為使用者進行授權:

1 mysql> grant all on *.* to user_name@'%' identified by 'user_password'; 

2 #或者 

3 mysql> grant all privileges on *.* to username@"%" identified by "password";  #(這句准) 

4 #或者 

5 CREATE USER 'test' @' 125.76.229.113' IDENTIFIED BY '26756880'; 

6 CREATE USER 'test'@' 125.76.229.215' IDENTIFIED BY '26756880'; 

7 CREATE USER 'test'@' 60.195.252.106' IDENTIFIED BY '26756880';

上面的命令授予的使用者權限可以訪問mysql中的任意資料庫(database)和表(table)。
完成上面的兩個步驟,重啟mysql即可在遠程登陸mysql伺服器了。Mysql的重啟命令如下:

查看原始碼列印協助1 sudo /etc/init.d/mysql restart

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.