gpt4 book ai didi

mysql - 无法连接到 mysql 127.0.0.1 但可以连接到本地主机

转载 作者:行者123 更新时间:2023-11-29 01:39:44 30 4
gpt4 key购买 nike

C:\Users\dp\Desktop>mysql -u user -pXXXX -h 127.0.0.1 -P 3306
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'mywayuser'@'localhost' (using passwo
rd: YES)

C:\Users\dp\Desktop>mysql -u user -pXXXX -h localhost -P 3306
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.6.21-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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> exit

我已经授予 127.0.0.1 的所有权限。

我做错了什么?

最佳答案

user@localhostuser@127.0.0.1 是 MySql 中的不同凭据。对于 Mysql,localhost 的主机基本上是“通过套接字连接,而不是 IP”。

要在尝试时通过套接字显式连接到本地主机,您需要在 mysql.user 表中的 localhost 处为所需用户专门设置一个条目:

 CREATE USER 'user'@'localhost'  IDENTIFIED BY PASSWORD 'xxxxx';

即使是 catch all "%"也行不通。如果你想使用它,你必须有一个 localhost 条目。然后授予该用户权限。

或者您可以使用 ip 127.0.0.1 或映射到 127.0.0.1 的任何其他主机名进行连接,而不是特殊主机 localhost

mysql -u user -pXXXX -h 127.0.0.1 -P 3306

是的,如果 mysql 不这样对待 localhost,我会更喜欢,但它就是......

关于mysql - 无法连接到 mysql 127.0.0.1 但可以连接到本地主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28098911/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com