解决ERROR 1044 (42000): Access denied for user

时间:2020-12-05 19:22:17

解决ERROR 1044 (42000): Access denied for user

ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

刚在服务器上装上mysql,发现以root加密码的方式总是登录不了,而直接输入mysql则直接就可以登录了。或者以mysql –u root方式可以登录,但是实习上登录上去也是一个空用户(''@'localhost'),不是root用户,看不了其他数据库。

干货,删除空用户方法                                                               

1.关闭mysql

service mysqld stop

或者

/etc/init.d/mysql stop

2.屏蔽权限

mysqld_safe --skip-grant-table

屏幕出现: Starting demo from .....
3.新开起一个终端输入

mysql -u root mysql
mysql> delete from user where USER='';
mysql> FLUSH PRIVILEGES;
mysql> \q

4.关闭所有终端,重启或者开启mysql。

干货,为root设置密码                                                                

1.关闭mysql

service mysqld stop

2.屏蔽权限

mysqld_safe --skip-grant-table

屏幕出现: Starting demo from .....
3.新开起一个终端输入

mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> \q
 
  


转自:https://blog.csdn.net/chun8416/article/details/50177117