为什么 GRANT 在 MySQL 中不起作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3886717/
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 17:22:35  来源:igfitidea点击:

Why is GRANT not working in MySQL?

mysqlgrant

提问by Christopher

I'm scratching my head on this one as I see a ton of helper websites showing how to create MySQL users and grant privileges but for some reason it just does not work for me. I tried on both WinXP and a MacBook Pro laptop with the latest MySQL version installed.

当我看到大量帮助网站展示如何创建 MySQL 用户和授予权限时,我正在摸索这个问题,但由于某种原因,它对我不起作用。我在安装了最新 MySQL 版本的 WinXP 和 MacBook Pro 笔记本电脑上进行了尝试。

The following is just an example from when I worked with WordPress. The actual database is something different but same issues.

以下只是我使用 WordPress 时的一个示例。实际的数据库是不同但相同的问题。

Here are the steps:

以下是步骤:

mysql> mysql -uroot -p<password>
mysql> CREATE DATABASE wwordpress;
mysql> CREATE USER 'www'@'localhost' IDENTIFIED BY 'basic';

Query OK, 0 rows affected (0.14 sec)

查询正常,0 行受影响(0.14 秒)

mysql> GRANT INSERT ON wordpress.* TO 'www'@'localhost' IDENTIFIED BY 'basic';

Query OK, 0 rows affected (0.00 sec)

查询正常,0 行受影响(0.00 秒)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.03 sec)

查询正常,0 行受影响(0.03 秒)

mysql> SELECT * FROM mysql.user WHERE User='www' \G
*************************** 1. row ***************************
                 Host: localhost
                 User: www
             Password: *E85C94AF0F09C892339D31CF7570A970BCDC5805
          Select_priv: N
          Insert_priv: N
          Update_priv: N
          Delete_priv: N
          Create_priv: N
            Drop_priv: N
          Reload_priv: N
        Shutdown_priv: N
         Process_priv: N
            File_priv: N
           Grant_priv: N
      References_priv: N
           Index_priv: N
           Alter_priv: N
         Show_db_priv: N
           Super_priv: N
Create_tmp_table_priv: N
     Lock_tables_priv: N
         Execute_priv: N
      Repl_slave_priv: N
     Repl_client_priv: N
     Create_view_priv: N
       Show_view_priv: N
  Create_routine_priv: N
   Alter_routine_priv: N
     Create_user_priv: N
           Event_priv: N
         Trigger_priv: N
             ssl_type:
           ssl_cipher:
          x509_issuer:
         x509_subject:
        max_questions: 0
          max_updates: 0
      max_connections: 0
 max_user_connections: 0
1 row in set (0.00 sec)

mysql>

As you can see "Insert_priv: N" should be "Y".

如您所见,“Insert_priv: N”应为“Y”。

Any suggestions?

有什么建议?

Thanks in advance.

提前致谢。

采纳答案by The Surrican

what you are selecting are the global privileges. you are however giving database (and host, but that doesnt matter) specific privileges.

您选择的是全局权限。但是,您正在授予数据库(和主机,但这并不重要)特定的权限。

GRANT INSERTON wordpress.* TO 'www'@'localhost' IDENTIFIED BY 'basic';

GRANT INSERTON wordpress.* TO 'www'@'localhost' IDENTIFIED BY 'basic';

theese permissions are stored in the dbtable.

这些权限存储在db表中。

just to point you in the right direction:

只是为了给你指明正确的方向:

SHOW GRANTS FOR 'www'@'localhost'

http://dev.mysql.com/doc/refman/5.0/en/show-grants.html

http://dev.mysql.com/doc/refman/5.0/en/show-grants.html

回答by martin clayton

That's not where the most user GRANTed rights are stored - try

这不是存储大多数用户授予权限的地方 - 尝试

SHOW GRANTS FOR 'www'@'localhost'

to see database-specific permissions instead. (A grant would only show up in the user table if it was for all databases.)

改为查看特定于数据库的权限。(如果授予所有数据库,则授权只会显示在用户表中。)

Here's a (rather old) step-by-step detail of how permissions are storedin MySQL - I don't think things have changed much.

这是有关如何在 MySQL中存储权限的(相当旧的)分步详细信息- 我认为事情没有太大变化。

回答by Ethicalguy Gopal Bogati

This should work:

这应该有效:

GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';

回答by Titus Kamau Mbugua

You need to look at mysql.db or mysql.tables_priv tables if you need to select the Y or N if you are trying to do some restrictions of from what page a user can edit or insert or delete... This tables are automatically updated with the Ys and Ns as they are solely designed to show what privileges a user has on tables or columns as opposed to mysql.user whose purpose is to show that there is a certain user who can login(create connection) to a database.

您需要查看 mysql.db 或 mysql.tables_priv 表,如果您需要选择 Y 或 N 如果您尝试对用户可以编辑或插入或删除的页面进行一些限制...这些表会自动更新使用 Ys 和 Ns,因为它们仅用于显示用户对表或列的权限,而不是 mysql.user,其目的是显示某个用户可以登录(创建连接)到数据库。