解决mysql登录错误:'Access denied for user 'root'@'localhost'
首先是不知道怎么忽然mysql用命令行,workbench都登录不了,都提示'Access denied for user 'root'@'localhost'。
数据库卸载重装了几次都不行。好像感觉数据清理不干净。解决的过程遇到的坑,这里记录分享下。
有效的操作记录下:
1、首先是跳过权限登录mysql,查看user表,
停止mysql服务~$ sudo service mysql stop
以安全模式启动MySQL~$ sudo mysqld_safe --skip-grant-tables &
注意:
可能提示mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exist
解决方法:(笔者尝试发现必须加sudo)
sudo mkdir -p /var/run/mysqld sudo chown mysql:mysql /var/run/mysqld
再次执行上面安全模式启动mysql ~$ sudo mysqld_safe --skip-grant-tables &
这次提示语句显示了,mysqld_safe Staring mysqld deamon with database from /var/lib/mysql
这次登录可以不用密码:mysql -u root 回车就登录了
sql语句查询mysql.user表的情况,如下:
加图片(以后补)
还有人提议如下这么做,没尝试
Open & Edit /etc/my.cnf or /etc/mysql/my.cnf, depending on your distro.
Add skip-grant-tables under [mysqld]
2、发现user的plugin为socket_plugin,改为mysql_native_password
修改root的plugin权限:
update mysql.user set authentication_string=PASSWORD('newPwd'), plugin='mysql_native_password' where user='root'; flush privileges; quit;
(注意这里修改一定要正确,免得跟笔者一样,粗心的把plugin修改的内容少些了一个字母,又有下面的折腾)
3、user表还有其他用户,root不能登录,用其他的用户登录也行啊。查询了发现一下有效操作:
在mysql的安装目录,一般在 /etc/mysql里面有个debain.cnf文件,里面有user,password,用这个用了登录,密码最后复制,然后就又可以修改user表root的plugin,操作同上。
重启mysql服务, sudo service mysql restart;
用root用户就可以登录。
参考博客:
MySQL ERROR 1698 (28000) 错误 https://www.jb51.net/article/117566.htm
mysql 查看当前使用的配置文件my.cnf的方法 https://www.jb51.net/article/110395.htm
linux -- Ubuntu查看修改mysql的登录名和密码、安装phpmyadmin https://www.jb51.net/article/174925.htm
总结
以上所述是小编给大家介绍的解决mysql登录错误:''Access denied for user ''root''@''localhost'',希望对大家有所帮助!
- MySQL8.0登录时出现Access denied for user ‘root‘@‘localhost‘ (using password: YES) 拒绝访问的完美解决
- 解决MySQL登录报错1045-Access denied for user 'root'@' '(using password:YES)
- 解决Mysql:ERROR 1045 (28000):Access denied for user ‘root‘@‘localhost‘ (using password: NO)的方法
- 解决mysql:ERROR 1045 (28000): Access denied for user ''root''@''localhost'' (using password: NO/YES)
- ubuntu18.0.4安装mysql并解决ERROR 1698 (28000): Access denied for user ''''root''''@''''localhost''''
- win10下MySQL 8.0登录Access denied for user‘root’@‘localhost’ (using password: YES)问题的解决方法
- 解决mysql ERROR 1045 (28000)-- Access denied for user问题
- 解决mysql创建数据库后出现:Access denied for user ''root''@''%'' to database ''xxx''的问题
- mysql Access denied for user ‘root’@’localhost’ (using password: YES)解决方法
- MySQL登录时出现 Access denied for user ‘root‘@‘xxx.xxx.xxx.xxx‘ (using password: YES) 的原因及解决办法
相关文章
MySQL中distinct与group by之间的性能进行比较
这篇文章主要针对MySQL中distinct与group by之间的性能进行比较,内容比较详细,很直观的能看出比较结果,感兴趣的小伙伴们可以参考一下2015-11-11MySQL中Distinct和Group By语句的基本使用教程
这篇文章主要介绍了MySQL中Distinct和Group By语句的基本使用教程,这里主要是针对查询结果去重的用法,需要的朋友可以参考下2015-12-12
最新评论