1. 程式人生 > >mysql版本:'for the right syntax to use near 'identified by 'password' with grant option'

mysql版本:'for the right syntax to use near 'identified by 'password' with grant option'

查詢mysql具體版本

SELECT @@VERSION

問題分析:mysql版本8.0.13,在給新使用者授權時,發生了變化:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by  'password' with grant option' at line 5, Time: 0.000000s

出錯的語句:

grant all privileges on *.* to 'root'@'172.16.10.203' identified by  'password' with grant option

修正後的語句:分開三次執行

#建立賬戶
create user 'root'@'172.16.10.203' identified by  'password'

#賦予許可權,with grant option這個選項表示該使用者可以將自己擁有的許可權授權給別人
grant all privileges on *.* to 'root'@'172.16.10.203' with grant option

#改密碼&授權超使用者,flush privileges 命令本質上的作用是將當前user和privilige表中的使用者資訊/許可權設定從mysql庫(MySQL資料庫的內建庫)中提取到記憶體裡
flush privileges;

原因分析 :此版的的mysql版本把將建立賬戶和賦予許可權分開了。

建立賬戶::create user ‘使用者名稱’@‘訪問主機’ identified by ‘密碼’;
賦予許可權:grant 許可權列表 on 資料庫 to ‘使用者名稱’@‘訪問主機’ ;
with grant option這個選項表示該使用者可以將自己擁有的許可權授權給別人