解决MYSQL远程连接出现1045的错误

解决远程连接出现1045的错误
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO
这里贴了一个别人写的解决文档

# mysql -u root -p 
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO

或者 
# mysql -u root -p password ‘newpassword’
Enter password:
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘root’@’localhost’ (using password: YES)’ 


出现此错误时:

1.关闭  

sudo service mysqld stop 

2.屏蔽权限   

mysqld_safe --skip-grant-table

屏幕出现: Starting demo from …..   

3.新开起一个终端输入  

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