MYSQL添加遠端使用者或允許遠端存取三種方法

來源:互聯網
上載者:User

標籤:mysql   許可權   

添加遠端使用者admin密碼為password GRANT ALL PRIVILEGES ON *.* TO [email protected] IDENTIFIED BY \‘password\‘ WITH GRANT OPTION GRANT ALL PRIVILEGES ON *.* TO [email protected]\"%\" IDENTIFIED BY \‘password\‘ WITH GRANT OPTION

mysql教程添加遠端使用者或允許遠端存取三種方法

用root使用者登陸,然後:

grant all privileges on *.* to 建立的使用者名稱 @"%" identified by "密碼";

flush privileges;   * 重新整理剛才的內容*

格式:grant 許可權 on 資料庫教程名.表名 to 使用者@登入主機 identified by "使用者密碼";

            @ 後面是訪問mysql的用戶端ip地址(或是 主機名稱) % 代表任意的用戶端,如果填寫 localhost 為

本地訪問(那此使用者就不能遠端存取該mysql資料庫了)。

同時也可以為現有的使用者佈建是否具有遠端存取許可權。如下:

use mysql;

update db set host = ‘%‘ where user = ‘使用者名稱‘; (如果寫成 host=localhost 那此使用者就不具有遠端存取許可權)

flush privileges;

grant all privileges on *.* to ‘myuser‘@‘%‘ identified by ‘mypassword‘ with grant option;

 

 

方法二

1.  使用grant語句添加:首先在資料庫本機上用root使用者

登入mysql(我是用遠端控制linux伺服器,相當於在伺服器本機登入mysql了),然後輸入:

mysql>grant all privileges on *.* to [email protected] identified by ‘something‘ with grant option;

添加一個使用者admin並授權通過本地機(localhost)訪問,密碼"something"。

 mysql>grant all privileges on *.* to [email protected]"%" identified by ‘something‘ with grant option;

添加一個使用者admin並授權可從任何其它主機發起的訪問(萬用字元%)。使用這一條語句即可。

2.使用insert語句:

mysql>insert into user values(‘%‘,‘admin‘,password(‘something‘), ‘y‘,‘y‘,‘y‘,‘y‘,‘y‘,‘y‘,

‘y‘,‘y‘,‘y‘,‘y‘,‘y‘,‘y‘,‘y‘,‘y‘)

   使用者資訊可在mysql資料庫中的users表中查看,這裡不在介紹了就。數清y的個數哦。

   好了,使用admin帳號串連試試看,我是屢試屢成功哦,呵呵!

方法三

添加遠端使用者admin密碼為password 
grant all privileges on *.* to [email protected] identified by ‘password‘ with grant option 
grant all privileges on *.* to [email protected]"%" identified by ‘password‘ with grant option


由於項目開發的要求資料庫的設計不得不用遠程模式。但是資料庫的遠程設定並沒那麼簡單,該項目的資料庫是mysql5.0。剛開始以為只要裝了資料庫伺服器就可以進行遠程連結了,但是mysql的設定是為了使用者的安全,系統預設的設定是不允許遠端使用者串連,只能本地的使用者串連。只要我們設定下系統的管理使用者的host這一項的值就可以給遠端使用者訪問了。

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.