mysql改密码1044_mysql重置密码和mysql error 1044(42000)错误

#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;

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误通常表示MySQL拒绝了'root'用户从任何主机连接到指定的数据库。有几种可能的原因和解决方法: 1. 权限问题:请确保'root'用户具有访问数据库的权限。你可以使用以下命令登录到MySQL服务器并检查用户权限: ``` mysql -u root -p SHOW GRANTS FOR 'root'@'%'; ``` 如果没有正确的权限,你可以使用以下命令为'root'用户授予访问数据库的权限: ``` GRANT ALL PRIVILEGES ON database_name.* TO 'root'@'%'; FLUSH PRIVILEGES; ``` 在上述命令中,将`database_name`替换为你想要访问的数据库名称。 2. 主机限制:如果MySQL服务器配置了主机限制,'root'用户可能被限制只能从特定的主机连接。你可以使用以下命令查看主机限制: ``` SELECT user,host FROM mysql.user WHERE user='root'; ``` 如果'root'用户的主机字段是特定的IP地址或主机名而不是通配符 '%',那么只有来自该主机的连接将被允许。你可以使用以下命令更新主机字段以允许来自任何主机的连接: ``` UPDATE mysql.user SET host='%' WHERE user='root'; FLUSH PRIVILEGES; ``` 3. 密码问题:确保你使用的是正确的密码来连接MySQL服务器。如果你不确定密码是否正确,可以尝试重置'root'用户的密码。 ``` mysql -u root -p ALTER USER 'root'@'%' IDENTIFIED BY 'new_password'; FLUSH PRIVILEGES; ``` 在上述命令中,将`new_password`替换为你想要设置的新密码。 请注意,在生产环境中,为了安全起见,建议不要在远程主机上使用'root'用户进行数据库连接。最好创建一个具有适当权限的新用户,并使用该用户进行连接。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值