mysql建立遠端使用者並授權

來源:互聯網
上載者:User

標籤:建立   test   ...   ddr   create   操作   root   沒有許可權   --   

今天需要在本地測試系統功能,因為本地沒有資料庫,就需要在程式裡面串連遠端資料庫;

先用ssh登入遠程伺服器,用root連上資料庫看看情況;

mysql> select Host,User,Password from mysql.user;+----------------+------------------+-------------------------------------------+| Host           | User             | Password                                  |+----------------+------------------+-------------------------------------------+| localhost      | root             | *836E233974EBE6EA32F95F890A91363F8427F78B || iz94926clkiz   | root             | *836E233974EBE6EA32F95F890A91363F8427F78B || 127.0.0.1      | root             | *836E233974EBE6EA32F95F890A91363F8427F78B || ::1            | root             | *836E233974EBE6EA32F95F890A91363F8427F78B || localhost      | debian-sys-maint | *1460ED3535ABDBB887F9E5F57F40A2354610CDF3 |+----------------+------------------+-------------------------------------------+5 rows in set (0.00 sec)

一共有5個mysql帳號,Host列可以看出來,這些帳號都只支援伺服器本機串連,現在我們來建立一個遠端使用者;

create user test identified by ‘123456‘;
+----------------+------------------+-------------------------------------------+| Host           | User             | Password                                  |+----------------+------------------+-------------------------------------------+| localhost      | root             | *836E283974EBE6EA32F95F890A91363F8427F78B || iz949s6clkiz   | root             | *836E283974EBE6EA32F95F890A91363F8427F78B || 127.0.0.1      | root             | *836E283974EBE6EA32F95F890A91363F8427F78B || ::1            | root             | *836E283974EBE6EA32F95F890A91363F8427F78B || localhost      | debian-sys-maint | *1460ED35E5ABDBB887F9E5F57F40A2354610CDF3 || %              | test             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |+----------------+------------------+-------------------------------------------+6 rows in set (0.00 sec)

建立完成了,在程式裡面串連發現還是沒有許可權,剛才我們只是建立了使用者,還沒有對這個使用者指派許可權;

grant all privileges on *.* to ‘test‘@‘%‘identified by ‘123456‘ with grant option;

 

all代表接受所有操作,比如 select,insert,delete....; *.* 代表所有庫下面的所有表;% 代表這個使用者允許從任何地方登入;為了安全期間,這個%可以替換為你允許的ip地址;

然後重新整理mysql使用者權限相關表;

flush privileges ;

 

我以為就此收工了,等等,程式怎麼還是連不上去,還是 access deny ;

難道連接埠不是3306嗎,開啟 mysql設定檔,是預設的3306,接著往下面看,發現一個關鍵地方;

bind-address           = 127.0.0.1

 

原來這裡mysql預設綁定了本地ip,不接受其他來源;注釋掉,重啟mysql 一切OK;

還有兩個常用操作;

修改指定使用者密碼

update mysql.user set password=password(‘新密碼‘) where User="test" and Host="localhost";

 

刪除使用者

delete from user where User=‘test‘ and Host=‘localhost‘;

 

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.