ubuntu下,ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)的解决方案

环境:ubuntu 16.04

1.命令行输入:sudo subl /etc/mysql/mysql.conf.d/mysqld.cnf

在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程

保存文档并退出

2.接下来我们需要重启MySQL:/etc/init.d/mysql restart

显示如下:

[....] Restarting mysql (via systemctl): mysql.serviceFailed to add /run/systemd/ask-password to directory watch: No space left on device

. ok 

3.重启之后输入#mysql即可进入mysql。

4.接下来就是用sql来修改root的密码

mysql> use mysql;
mysql>update mysql.user set authentication_string=password('123456') where user='root';
mysql> flush privileges;
mysql> quit

到这里root账户就已经重置成新的密码了。

5. sudo subl /etc/mysql/mysql.conf.d/mysqld.cnf

编辑mysqld.cnf,去掉刚才添加的内容,然后重启MySQL, 

/etc/init.d/mysql restart 大功告成!





猜你喜欢

转载自blog.csdn.net/weixin_42193179/article/details/80350911