gpt4 book ai didi

Mysql 本地主机!= 127.0.0.1?

转载 作者:IT老高 更新时间:2023-10-28 23:52:35 25 4
gpt4 key购买 nike

$ mysql -u root -h 127.0.0.1 -e 'show tables' created_from_host;
+-----------------------------+
| Tables_in_created_from_host |
+-----------------------------+
| test |
+-----------------------------+

$ mysql -u root -h localhost -e 'show tables' created_from_host;
ERROR 1049 (42000): Unknown database 'created_from_host'

$ cat /etc/hosts
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost
::1 localhost6.localdomain6 localhost6

怎么可能呢?主要问题 - 如何从所有主机授予 root 对所有数据库的所有权限?

更新:

$ mysql -u root -h 127.0.0.1 -pzenoss -e "show grants";
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*3715D7F2B0C1D26D72357829DF94B81731174B8C' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
$ mysql -u root -h localhost -pzenoss -e "show grants";
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*3715D7F2B0C1D26D72357829DF94B81731174B8C' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+

UPD2:

zends> SHOW GLOBAL VARIABLES LIKE 'skip_networking';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| skip_networking | OFF |
+-----------------+-------+
1 row in set (0.00 sec)

zends> SELECT user,host FROM mysql.user WHERE user='root';
+------+-----------------------+
| user | host |
+------+-----------------------+
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
| root | localhost.localdomain |
+------+-----------------------+
4 rows in set (0.00 sec)

最佳答案

如你所见here , 如果在没有主机名的情况下使用或使用主机名localhost,则 UNIX mysqld 使用套接字。

所以它产生了差异,并且在 GRANT 系统中这种差异变得很明显。

关于Mysql 本地主机!= 127.0.0.1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19712307/

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