创建mysql连接 1045_mysql连接navicat的时候报错1045怎么解决?

当出现MySQL连接是出现1045错误时,以下举例仅供参考。

一、连接错误的主机

[root@localhost ~]# mysql -u root -p123456mysql: [Warning] Using a password on the command line interface can be insecure.ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

如果未指定要连接的主机(使用 -h 标志),则 MySQL 客户端将尝试连接到 localhost 实例,同时您可能尝试连接到另一个主机端口实例。

修复:仔细检查您是否尝试连接到 localhost,或者确保指定主机和端口(如果它不是 localhost):

[root@localhost ~]# mysql -u root -p123456 -h -P 3306

二、用户不存在

[root@localhost ~]# mysql -u nonexistant -p123456 -h localhostmysql: [Warning] Using a password on the command line interface can be insecure.ERROR 1045 (28000): Access denied for user 'nonexistant'@'localhost' (using password: YES)

修复:仔细检查用户是否存在:

mysql> SELECT User FROM mysql.user WHERE User='nonexistant';Empty set (0.00 sec)

如果用户不存在,请创建一个新用户:

mysql> CREATE USER 'nonexistant'@'localhost' IDENTIFIED BY 'sekret';

Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.01 sec)

三、用户存在但客户端主机无权连接

[root@localhost ~]# mysql -u nonexistant -p123456mysql: [Warning] Using a password on the command line interface can be insecure.ERROR 1045 (28000): Access denied for user 'nonexistant'@'localhost' (using password: YES)

修复:您可以通过以下查询检查 MySQL 允许连接的主机用户/主机:

mysql> SELECT Host, User FROM mysql.user WHERE User='nonexistant';+-------------+-------------+| Host | User |+-------------+-------------+| 192.168.0.1 | nonexistant |+-------------+-------------+1 row in set (0.00 sec)

如果需要检查客户端连接的 IP,可以使用以下 Linux 命令来获取服务器 IP:

[root@localhost ~]# ip address | grep inet | grep -v inet6 inet 127.0.0.1/8 scope host lo inet 192.168.0.20/24 brd 192.168.0.255 scope global dynamic wlp58s或公共IP:

[root@localhost ~]# dig +short http://myip.opendns.com @resolver1.opendns.com177.128.214.181

然后,您可以创建具有正确主机(客户端 IP)的用户,或使用'%'(通配符)来匹配任何可能的 IP:

mysql> CREATE USER 'nonexistant'@'%' IDENTIFIED BY '123456';Query OK, 0 rows affected (0.00 sec)

四、密码错误,或者用户忘记密码

mysql> CREATE USER 'nonexistant'@'%' IDENTIFIED BY '123456';Query OK, 0 rows affected (0.00 sec)

修复:检查和/或重置密码:您无法从 MySQL 以纯文本格式读取用户密码,因为密码哈希用于身份验证,但您可以将哈希字符串与“PASSWORD”函数进行比较:

mysql> SELECT Host, User, authentication_string, PASSWORD('forgotten') FROM mysql.user WHERE User='nonexistant';+-------------+-------------+-------------------------------------------+-------------------------------------------+| Host | User | authentication_string | PASSWORD('forgotten') |+-------------+-------------+-------------------------------------------+-------------------------------------------+| 192.168.0.1 | nonexistant | *AF9E01EA8519CE58E3739F4034EFD3D6B4CA6324 | *70F9DD10B4688C7F12E8ED6C26C6ABBD9D9C7A41 || % | nonexistant | *AF9E01EA8519CE58E3739F4034EFD3D6B4CA6324 | *70F9DD10B4688C7F12E8ED6C26C6ABBD9D9C7A41 |+-------------+-------------+-------------------------------------------+-------------------------------------------+2 rows in set, 1 warning (0.00 sec)

我们可以看到 PASSWORD('forgotten')哈希与 authentication_string 列不匹配,这意味着 password string ='forgotten' 不是正确的登录密码。如果您需要覆盖密码,可以执行以下查询:

mysql> set password for 'nonexistant'@'%' = 'hello$!world';Empty set (0.00 sec)

五、Bash 转换密码中的特殊字符

[root@localhost ~]# mysql -u nonexistant -phello$!worldmysql: [Warning] Using a password on the command line interface can be insecure.ERROR 1045 (28000): Access denied for user 'nonexistant'@'localhost' (using password: YES)

修复:通过在单引号中包装密码来防止 bash 解释特殊字符:

[root@localhost ~]# mysql -u nonexistant -p'hello$!world'mysql: [Warning] Using a password on the command line interface can be insecure...mysql>

六、SSL 是必须的,但客户没有使用

mysql> create user 'ssluser'@'%' identified by '123456';

Query OK, 0 rows affected (0.00 sec)

mysql> alter user 'ssluser'@'%' require ssl;

Query OK, 0 rows affected (0.00 sec)

...

[root@localhost ~]# mysql -u ssluser -p123456

mysql: [Warning] Using a password on the command line interface can be insecure.

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

修复:添加 -ssl-mode 标志(-ssl 标志已弃用但也可以使用)

[root@localhost ~]# mysql -u ssluser -p123456 --ssl-mode=REQUIRED...mysql>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Navicat连接MySQL报错1045通常是因为用户名或密码错误导致的。请检查你在Navicat中输入的用户名和密码是否正确,并确保该用户具有连接到所需数据库的权限。如果仍然无法解决问题,可以尝试在MySQL命令行中使用相同的用户名和密码进行连接,以确认用户名和密码是否正确。 ### 回答2: Navicat连接MySQL时出现错误1045是由于用户名或密码输入错误导致的。这意味着您输入的用户名或密码与MySQL数据库中存储的不匹配。请按照以下步骤尝试解决此问题: 1. 首先,请确保您使用的是正确的用户名和密码。查看您的MySQL数据库配置以确认登录信息是否正确。默认情况下,用户名一般为root,密码为空。 2. 如果用户名和密码是正确的,则可能是权限问题导致的。请检查您是否已向该用户授予了正确的权限,以对目标数据库执行所需的操作。您可以查询MySQL官方文档以了解如何为MySQL用户授予权限。 3. 还可以尝试刷新MySQL服务器。在Navicat中通过右键单击服务器,选择“刷新”选项。 4. 如果您的MySQL服务器在Linux上运行,则需要确保防火墙已正确配置以允许数据库服务器接受传入连接。如果您已经在特定的IP地址上设置了MySQL服务器,则需要确保客户端尝试连接的IP地址与该地址匹配。 如果上述步骤都没有解决问题,您可以尝试重新安装MySQL服务器或使用Navicat的备份文件。最后,如果问题仍然存在,请联系MySQL技术支持团队以获取进一步的帮助。 ### 回答3: 当navicat连接mysql时,出现报错1045的情况,一般是因为用户没有权限或者密码错误所引起的。下面提供一些排查问题的方法: 1.检查用户名和密码是否正确。在navicat中选择连接时,确认用户名和密码是否正确。可以登录到mysql命令行中,执行"select user,host,password from mysql.user;"来查看所有用户的用户名和密码是否正确。 2.检查权限。确认该用户是否有访问该数据库的权限。可以通过在mysql命令行中执行"show grants for `username`@`%`;"或者"show grants for `username`@`hostname`;"来查看用户权限信息。 3.检查mysql服务器防火墙。如果mysql服务器未配置防火墙或者防火墙设置不正确,可能会导致navicat连接mysql失败。可以检查防火墙是否开启端口3306以允许外部访问。 4.更新navicat客户端版本。navicat客户端版本过低或不兼容mysql版本也可能导致连接失败。可以更新navicat客户端到最新版本或者检查mysql版本是否兼容navicat版本。 5.重置密码。如果以上方法都不能解决问题,可以尝试重置mysql用户密码。可以在mysql命令行中执行"update mysql.user set password=password('new_password') where user='username';"来更新用户密码。 总之,当navicat连接mysql出现报错1045时,需要检查用户名密码、权限、防火墙、navicat客户端版本及mysql用户密码等问题,来排查并解决问题。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值