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

标签 mysql localhost privileges sql-grant

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/

相关文章:

windows - 程序如何请求管理员权限?

mysql - 无法在 WAMP 服务器上的 WordPress 本地主机中选择数据库错误

localhost - 我的第一个 NUXT.js 应用程序拒绝在本地主机 :3000 上运行

node.js - Chrome 无法连接到 http ://localhost:8080 but http://127. 0.0.1:8080 有效

c++ - AdjustTokenPrivileges 错误 6 - 句柄无效

mysqld_safe --skip-grant-tables 未在 IBM i (AS400/iseries) 中启动

PHP mySQL 在大量插入语句上出现性能问题,我应该使用其他方法吗?

mysql - 如何用sql获取按周滚动的数据集

php - 优化页面充电时间(使用 Eloquent 请求)

php - mysql_num_rows 和条件