標籤:建立 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建立遠端使用者並授權