在测试环境中,我以如下方式创建了一个名相同的用户和一个DB:
create user 'test'@'localhost' identified by 'blablabla';
create database test;当我以这种方式将用户与DB关联时(同时还将所有权限授予用户):
grant all privileges on test.* to test; 错误1133 (42000):找不到用户表中的任何匹配行
我不明白什么不匹配。因为show databases;和SELECT user FROM mysql.user;提示用户和DB都是成功创建的,所以我不知道为什么会出现这个错误。
为什么我会有这个错误?
Abhik的
mysql> grant all privileges on test.* to 'test'@'localhost';
grant all privileges on test.* to 'test'@'localhost';
^C
mysql> grant all privileges on test.* to 'test'@'localhost';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 4774
Current database: *** NONE ***
Query OK, 0 rows affected (0.00 sec)发布于 2017-11-17 11:14:31
与PostgreSQL不同,MySQL和MariaDB不具有单用户名角色。没有定义主机名的用户test被解释为用户test@%,对于任何主机,它都是不同于test@localhost的用户,并且可以有完全不同的密码。
你会想做的
GRANT ALL PRIVILEGES ON test.* TO test@localhost;而不是。实际上,您可以完全省略单独的CREATE USER语句,并执行以下操作:
CREATE DATABASE test;
GRANT ALL PRIVILEGES ON test.* TO test@localhost IDENTIFIED BY 'password'; 剩下的就由MySQL来处理。
https://unix.stackexchange.com/questions/405175
复制相似问题