Linux學習筆記之——ubuntu中mysql允許遠端連線

來源:互聯網
上載者:User

標籤:

摘要:一般mysql預設安裝出於安全考慮、一般只會讓主機串連到mysql、而其他的機器通過遠端方式是串連不上mysql的。這樣想在別的機器上遠程操作主機的mysql就會denied、當然備份也會被拒絕。記錄一下如何解決mysql支援遠程。

一:簡介

環境依然是前面的環境、可以在其他機器上測試一下是否能遠端連線本主機的mysql。我主機的IP是192.168.26.200、mysql使用者是root、密碼是password、鍵入如下命令、並輸入密碼:

mysql–h192.168.26.200 –uroot –p

會提示:

ERROR 2003(HY000): Can‘t connect to MySQL server on ‘192.168.26.200‘ (111)

問題就是我們並沒有開啟主機、也就是192.168.26.200上的mysql的允許別人遠端配置。

二:解決過程 2.1 查看主機上mysql允許串連的機器IP

a) 登入mysql、輸入命令:

                mysql  –uroot  –p

b) 輸入密碼:

                password

c) mysql的相關許可權都在mysql這個內建的database內、查看user表的指定欄位

                select user,password , host from user where user = ‘root‘;                #會顯示如下                +------+-------------------------------------------+-----------+                | user |password                                  | host      |                +------+-------------------------------------------+-----------+                | root |*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 | localhost |                +------+-------------------------------------------+-----------+                說明root使用者登入下的mysql只允許localhost串連。
2.2 實現所有IP可以串連root使用者的mysql。

a) 修改root使用者下的mysql、即可以指定某些IP能夠串連、也可以指定所有的IP可以串連、這裡指定的是全部

b) 在上面的查看許可權介面執行如下語句:

                grant allprivileges on *.* to ‘root‘@‘%‘ identified by ‘password‘;                flushprivileges;

如果我們想指定IP串連、那麼可以將上面的%換成我們指定的IP、比如指定192.168.30.253可以串連

                grant allprivileges on *.* to ‘root‘@‘192.168.30.253‘ identified by ‘password‘;                flushprivileges;

修改mysql的設定檔 my.cnf中

                vim /etc/mysql/my.cnf                bind-address = 127.0.0.1                將 bind-address =127.0.0.1 這一行注釋掉, 即修改為:                 #bind-address = 127.0.0.1
2.3 測試

使用其他機器遠程登入試試:

                mysql -h192.168.26.200 -uroot –ppassword                #顯示如下資訊                Welcome to the MySQL monitor.  Commands end with ; or \g.                Your MySQL connection id is 413                Server version: 5.5.35-0ubuntu0.12.04.2(Ubuntu)                 Copyright (c) 2000, 2011, Oracle and/or itsaffiliates. All rights reserved.                 Oracle is a registered trademark of OracleCorporation and/or its                affiliates. Other names may be trademarksof their respective                owners.                 Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ toclear the current input statement.                 mysql>                 則登入成功
三: 補充 3.1 在window下修改mysql編碼:

修改mysql安裝目錄下的設定檔my.ini。將其中的latin1修改成utf8

3.2window下命令視窗啟動、停止mysql服務

停止:

                       net stop mysql

啟動:

                       net start mysql


Linux學習筆記之——ubuntu中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.