MySQL 在用户表中找不到任何匹配的行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17597144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:06:25  来源:igfitidea点击:

Can't find any matching row in the user table

mysql

提问by lapots

I am trying to execute this queries -

我正在尝试执行此查询 -

DROP DATABASE IF EXISTS `hotel`;

GRANT USAGE ON *.* TO 'user'@'localhost';
DROP USER 'user'@'localhost';

CREATE USER user@localhost IDENTIFIED BY 'user';

CREATE DATABASE `hotel`
    CHARACTER SET 'utf8'
    COLLATE 'utf8_general_ci';

GRANT USAGE ON *.* to 'user'@'localhost' identified by 'user';

But I always get error on

但我总是出错

GRANT USAGE ON *.* TO 'user'@'localhost' Error Code: 1133. Can't find any matching row in the user table    0.000 sec

I thought that Grant usagecreate new user if user does not exist. What is wrong?

我认为Grant usage如果用户不存在就创建新用户。怎么了?

采纳答案by Frambot

I thought that Grant usage create new user if user does not exist. What is wrong?

我认为如果用户不存在,则 Grant 用法会创建新用户。怎么了?

In previous versions of mysql that was the case. See this answerif you want to do it the new way. If you would like to modify your system settings to make it work the way it used to, read on. However, note that this is a deprecated behavior, as the linked documentation states that

在以前版本的 mysql 中就是这种情况。如果您想以新方式进行操作,请参阅此答案。如果您想修改系统设置以使其像以前一样工作,请继续阅读。但是,请注意,这是不推荐使用的行为,因为链接的文档指出

NO_AUTO_CREATE_USER will be removed in a future MySQL release, at which point its effect will be enabled at all times (GRANT will not create accounts)

NO_AUTO_CREATE_USER 将在未来的 MySQL 版本中删除,此时其效果将始终启用(GRANT 不会创建帐户)

From the documentation, you can set an option to allow mysql to create a user if it does not exist.

文档中,您可以设置一个选项以允许 mysql 在用户不存在时创建该用户。

NO_AUTO_CREATE_USER

Prevent the GRANT statement from automatically creating new users if it would otherwise do so, unless a nonempty password also is specified.

NO_AUTO_CREATE_USER

除非还指定了非空密码,否则阻止 GRANT 语句自动创建新用户,否则会这样做。

To set the option:

要设置选项:

You can change the SQL mode at runtime by using a SET [GLOBAL|SESSION] sql_mode='modes' statement to set the sql_mode system value.

您可以在运行时更改 SQL 模式,方法是使用 SET [GLOBAL|SESSION] sql_mode='modes' 语句设置 sql_mode 系统值。

回答by Ricardo Rivaldo

I got the same error with

我遇到了同样的错误

grant all on newdb.* to newuser@localhost;

solved with 'identified by':

用“识别”解决:

grant all on newdb.* to newuser@localhost  identified by 'password';

回答by rustyx

The GRANTcommand no longer automatically creates users.

GRANT命令不再自动创建用户。

Do not change the NO_AUTO_CREATE_USERvariable, instead first create the user using the CREATE USERcommand, thengrant the privileges:

不要更改NO_AUTO_CREATE_USER变量,而是首先使用CREATE USER命令创建用户,然后授予权限:

DROP USER IF EXISTS 'user'@'localhost';
CREATE USER 'user'@'localhost' IDENTIFIED BY 'pass';
GRANT ALL PRIVILEGES ON database_name.* TO 'user'@'localhost';

回答by Rauli Rajande

Try to add to the end of the script:

尝试添加到脚本的末尾:

FLUSH PRIVILEGES;