博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql重置密码和mysql error 1044(42000)错误
阅读量:6544 次
发布时间:2019-06-24

本文共 3055 字,大约阅读时间需要 10 分钟。

#mysql错误:(密码不正确,需要重置密码)

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

#编辑配置文件

[root@m1 mysql]# vi /roobo/server/mysql/my.cnf

[mysqld]

skip-grant-tables  

#修改完后重启服务

[root@m1 mysql]# /etc/init.d/mysqld restart

#登录数据库

[root@m1 mysql]# mysql

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.24-log Source distribution

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

mysql> use mysql;

mysql> update user set password=password("你的新密码") where user="root";
mysql> flush privileges;
mysql> quit

#再把vi my.cnf 配置文件中下面参数删除。

[mysqld]

skip-grant-tables  

#修改完后重启服务

[root@m1 mysql]# /etc/init.d/mysqld restart

#再用设置的密码登录

mysql -uroot -p

passwd:******

 


 

mysql error 1044(42000)错误

[root@m1 ~]# mysql -uroot -p

Enter password:
ERROR 1049 (42000): Unknown database '127.0.0.1'
[root@m1 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.6.24-log Source distribution

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

#授权

mysql> grant all on work.* to work@'192.168.1.4' identified by 'juan3652014';

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

 

原因:  授权需要WITH GRANT OPTION 才能授权,否则会报。

mysql> show grants for root@'localhost';

+----------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*F109C974766912D490ECD7E3C8754542FC773A49' |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION 
+----------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

 

解决方法:

#登录mysql

mysql -uroot -p -h 127.0.0.1

mysql> use mysql
Database changed
mysql> select user,host from user;
+--------+-------------+
| user | host |
+--------+-------------+
| root | 127.0.0.1 |
| rep | 192.168.1.% |
| work | 192.168.1.4 |
| root | localhost |
| zabbix | localhost |
+--------+-------------+
5 rows in set (0.00 sec)

#授权成功
grant all on work.* to work@'192.168.1.4' identified by 'juan3652014';
flush privileges;

 

 如上所示,账号没有WITH GRANT OPTION选项,关于WITH GRANT OPTION选项,如果想让授权的用户,也可以将这些权限授予给其他用户,需要选项 WITH GRANT OPTION 。也就是说有这个选项就可以将权限传递给第三方。这也是上面用户给其它用后授权报错的原因,如果以 root@127.0.0.1登录(此账号拥有WITHGRANT OPTION选项),创建用户并授权就不会有这个错误。

 

转载地址:http://hpodo.baihongyu.com/

你可能感兴趣的文章
spring中注解说明
查看>>
QLabel显示图片,图片可以自适应label的大小
查看>>
BZOJ3994:[SDOI2015]约数个数和——题解
查看>>
3、EJB3.0开发第一个无会话Bean和客户端(jboss4.2.3)
查看>>
git fetch & pull详解
查看>>
优酷2013.3去广告 不黑屏
查看>>
web入门、tomcat、servlet、jsp
查看>>
boost_1.63.0编译VS2013
查看>>
mysql查看每个数据库所占磁盘大小
查看>>
jQuery 插件-(初体验一)
查看>>
PHP语言 -- Ajax 登录处理
查看>>
基于js的CC攻击实现与防御
查看>>
Largest Rectangle in a Histogram
查看>>
树状数组模板
查看>>
我的家庭私有云计划-19
查看>>
项目实践中Linux集群的总结和思考
查看>>
关于使用Android NDK编译ffmpeg
查看>>
监控MySQL主从同步是否异常并报警企业案例模拟
查看>>
zabbix从2.2.3升级到最新稳定版3.2.1
查看>>
我有一个网站,想提高点权重
查看>>