2019独角兽企业重金招聘Python工程师标准>>>
最近新装好的mysql在进入mysql工具时,总是有错误提示:
# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
使用网上介绍的方法修改root用户的密码:
# mysqladmin -uroot -p password 'newpassword'
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
注意:也可以用 mysql安全设置 命令:
mysql_secure_installation
之后按如下步骤操作:
方法一:
# /etc/init.d/mysqld stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
注:5.7 版本的 Password 字段已经改名为 authentication_string; 所以密码语句需要修改为:
UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
# /etc/init.d/mysqld restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>
mysql>
# mysql -u root -p
Enter password: <输入新设的密码newpassword>
mysql>
问题解决了!