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.cnblogs.com/leolztang/p/5094930.html
mysql 查看当前使用的配置文件my.cnf的方法 https://blog.csdn.net/fdipzone/article/details/52705507
linux -- ubuntu查看修改mysql的登录名和密码、安装phpmyadmin https://www.cnblogs.com/hf8051/p/4775627.html
推荐阅读
-
[MySQL][ODBC 3.51 Driver]Access denied for user: 'root@local
-
Docker容器安装的mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'
-
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
-
linux mysql忘记密码的多种解决或Access denied for user 'root'@'localhost'
-
新装MySql后登录出现root帐号提示mysql ERROR 1045 (28000): Access denied for use的解决办法
-
linux mysql忘记密码的多种解决或Access denied for user 'root'@'localhost'
-
ERROR 1045 (28000): Access denied for user root@localhost (using password: NO)
-
连接本地数据库出现:1045 - Access denied for user 'root'@localhost'(using pass
-
ERROR 1045: Access denied for user: root@localhost (Using password: NO)
-
新装MySql后登录出现root帐号提示mysql ERROR 1045 (28000): Access denied for use的解决办法