问题解决:使用mysql -u root -p
登陆mysql时报错
eroor 1698(28000):Access denied for user 'root'
分析
安装mysql时没有设置密码,这个问题与ERROR 1045 (28000)
的解决方案一致
解决1,不彻底方案
使用sudo mysql
登陆mysql
解决2,彻底方案:
1.sudo vim /etc/mysql/debian.cnf
,这个文件里有MySQL默认的用户名和用户密码,
发现默认的用户名是debian-sys-maint
,password后是默认密码
2.使用默认的用户名与密码登陆sql : mysql -u debian-sys-maint -p
,发现可以登陆
3.修改密码:
mysql> update mysql.user set authentication_string=password('password') where user='root'and Host = 'localhost';
mysql>flush privileges;
显示Query OK,即更改成功。
4.重启mysql服务即可
sudo service mysql restart
else:
再次使用root和新密码登陆,如果出现MySQL ERROR 1698 (28000) 错误
1.使用sudo mysql
登陆;或停止mysql服务后,使用sudo mysqld_safe --skip-grant-tables &
以安全模式登陆。
2.输入下面指令:newPwd为你的密码
mysql> update mysql.user set authentication_string=PASSWORD('newPwd'),plugin='mysql_native_password' where user='root';
重启mysql服务 ,问题可以解决