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