mysql出现Access denied问题

ERROR 1044 (42000): Access denied for user  ''@'localhost'  to database 'mysql'。
原因:
       因为mysql数据库的user表里,存在用户名为空的账户即匿名账户,导致登录的时候是虽然用的是root,但实际是匿名登录的,通过错误提示里的
''@'localhost' 可以看出来。
解决方法:
方法一:

1.关闭mysql
# service mysqld stop                                                                                                             
2.屏蔽权限
# mysqld_safe --skip-grant-table                                                                                            
屏幕出现: Starting demo from .....
3.新开起一个终端输入

# mysql -u root 

mysql>use mysql                                                                                                              

mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';   
 mysql> FLUSH PRIVILEGES;//记得要这句话,否则如果关闭先前的终端,又会出现原来的错误
mysql> \q                                                                                                                               

方法二:
1.关闭mysql
# service mysqld stop                                                                                                             
2.屏蔽权限 
# mysqld_safe --skip-grant-table                                                                                           
屏幕出现: Starting demo from ..... 
3.新开起一个终端输入    

# mysql -u root 

mysql>use mysql   

mysql> delete from user where USER='';    
mysql> FLUSH PRIVILEGES;//记得要这句话,否则如果关闭先前的终端,又会出现原来的错误    
mysql> \q          

你可能感兴趣的:(mysql)