1.問題緣由:html
出現這是錯誤是由於 mysql 默認的 root 用戶使用了 UNIX auth_socket_plugin 的用戶認證方式,咱們有下面兩種方式處理問題:mysql
2.解決方案:sql
方法一:修改 root 用戶認證方式爲 mysql_native_password plugin數據庫
首先登錄MySQL使用sudo.服務器
sudo mysql -uroot
修改MySQL-root用戶的登錄方式.socket
1 USE mysql; 2 UPDATE user SET plugin=‘mysql_native_password‘ WHERE user=‘root‘; 3 FLUSH PRIVILEGES; 4 exit;
重啓MySQL服務,登錄root用戶.ide
1 sudo service mysql restart 2 mysql -u root # 初始安裝並無設置密碼,因此直接就能登陸了
方法二:建立新的MySQL User
Step1. Login in the mysql without passwd. post
sudo mysql -uroot
Setp2. Use the mysql database to setup the new User.url
use mysql; select user,host,plugin from user; create user 'pi'@'localhost' identified by 'mysql'; create user 'pi'@'%' identified by 'mysql'; update user set plugin='unix_socket' where user='pi'; select user,host,plugin from user; flush privileges;
Step3. Setting the privilige of the new user.spa
grant all privileges on * to pi@'localhost' identified by 'mysql'; grant all privileges on * to pi@'%' identified by 'mysql'; flush privileges;
1.PrivilegesCode表示授予的權限類型,經常使用的有如下幾種類型:
2.DbName.tableName表示授予權限的具體庫或表,經常使用的有如下幾種選項:
3.Username@host表示授予的用戶以及容許該用戶登陸的IP地址。其中Host有如下幾種類型:
Step4. Check the privilige of the user.
show grants for 'pi';
Delet a User :
drop user命令會刪除用戶以及對應的權限,執行命令後你會發現mysql.user表和mysql.db表的相應記錄都消失了。
drop user 'pi'@'%';
3.參考文獻:
1.ERROR 1698 (28000)Access denied for user 'root'@'localhost': http://www.mamicode.com/info-detail-2491371.html
2. MySQL用戶管理:添加用戶、受權、刪除用戶:http://www.javashuo.com/article/p-tqfoalcb-ct.html
3.MySQL用戶管理 :http://www.cnblogs.com/chanshuyi/p/mysql_user_mng.html