报错集:给新创建的MySQL数据库设置用户密码时报错(error: ‘Access denied for user ‘root‘@‘localhost‘ (using password: NO))
Posted handsomeboy-东
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了报错集:给新创建的MySQL数据库设置用户密码时报错(error: ‘Access denied for user ‘root‘@‘localhost‘ (using password: NO))相关的知识,希望对你有一定的参考价值。
[root@mysql mysql]# mysqladmin -u root -p password
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
错误原因:安装完MySQL数据库后它自行设置了临时密码
解决方法:设置MySQL的主配置文件,在最后添加 skip-grant-tables(慎用)用来免密登录MySQL数据库,然后在数据库里面修改密码
[root@mysql mysql]# systemctl stop mysqld.service #先停止MySQL数据库
[root@mysql mysql]# vim /etc/my.cnf
……………………
skip-grant-tables
保存退出
[root@mysql mysql]# systemctl start mysqld.service #再启动MySQL数据库
[root@mysql mysql]# mysql -u root ##进入MySQL数据库
mysql> select * from user; #以下为修复root用户权限设置
Database changed
mysql> select * from user;
3 rows in set (0.00 sec)
mysql> truncate table user;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to root@localhost identified by 'admin123' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> select host, user from user; #测试结果
+-----------+------+
| host | user |
+-----------+------+
| localhost | root |
+-----------+------+
1 row in set (0.00 sec)
mysql> exit
Bye
[root@mysql mysql]# systemctl restart mysqld.service #重启MySQL数据库
[root@mysql mysql]# mysql -u root -padmin123 #用新密码登录MySQL舒克即可
mysql>
以上是关于报错集:给新创建的MySQL数据库设置用户密码时报错(error: ‘Access denied for user ‘root‘@‘localhost‘ (using password: NO))的主要内容,如果未能解决你的问题,请参考以下文章
报错集:部署OpenStack时配置Rabbitmq时报错!
报错集:部署OpenStack时配置Rabbitmq时报错!