遇到了 SQLException: access denied for @'localhost' (using password: no)
解決辦法 grant all privileges on *.* to joe@localhost identified by '1';
flush privileges;
拿 joe 1 登陸
附:
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 joe@localhost identified by ‘123′;
給本機用戶joe分配可對所有數據庫的所有表進行所有操作的權限,並設定口令爲123。
mysql>grant all privileges on *.* to test@"%" identified by "1234";
//@"%" 表示對所有非本地主機授權,不包括localhost。(localhost地址設爲127.0.0.1,如果設爲真實的本地地址,不知道是否可以,沒有驗證。)
//對localhost授權:加上一句
mysql>grant all privileges on testDB.* to test@localhost identified by '1234';即可。
---------------------
附:刪除用戶
@>mysql -u root -p
@>密碼
mysql>Delete FROM user Where User='test' and Host='localhost';
mysql>flush privileges;
mysql>drop database testDB; //刪除用戶的數據庫
刪除賬戶及權限:>drop user 用戶名@'%';
>drop user 用戶名@ localhost;
修改指定用戶密碼
@>mysql -u root -p
@>密碼
mysql>update mysql.user set password=password('新密碼') where User="test" and Host="localhost";
mysql>flush privileges;