1. 程式人生 > >mysql 新建使用者並賦予許可權

mysql 新建使用者並賦予許可權

遇到了 SQLException: access denied for @’localhost’ (using password: no)
解決辦法

grant all privileges on *.* to [email protected] identified by '1';
flush privileges; 

附:

mysql> grant 許可權1,許可權2,…許可權n on 資料庫名稱.表名稱 to 使用者名稱@使用者地址 identified by ‘連線口令’;

許可權1,許可權2,…許可權n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14個許可權。
當權限1,許可權2,…許可權n被all privileges或者all代替,表示賦予使用者全部許可權。
當資料庫名稱.表名稱被.

代替,表示賦予使用者操作伺服器上所有資料庫所有表的許可權。
使用者地址可以是localhost,也可以是ip地址、機器名字、域名。也可以用’%’表示從任何地址連線。
‘連線口令’不能為空,否則建立失敗。

mysql>grant select,insert,update,delete,create,drop on vtdc.employee to [email protected] identified by ‘123′;
給來自10.163.225.87的使用者joe分配可對資料庫vtdc的employee表進行select,insert,update,delete,create,drop等操作的許可權,並設定口令為123。

mysql>grant all privileges on vtdc.* to [email protected] identified by ‘123′;
給來自10.163.225.87的使用者joe分配可對資料庫vtdc所有表進行所有操作的許可權,並設定口令為123。

mysql>grant all privileges on . to [email protected] identified by ‘123′;
給來自10.163.225.87的使用者joe分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123。

mysql>grant all privileges on .

to [email protected] identified by ‘123′;
給本機使用者joe分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123。