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

发布于 2024-09-26 10:33:31 字数 1879 浏览 5 评论 0原文

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

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

步骤如下:

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

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

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

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

mysql> FLUSH PRIVILEGES;

查询正常,受影响 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>

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

有什么建议吗?

提前致谢。

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.

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

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)

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

Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.03 sec)

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".

Any suggestions?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

混吃等死 2024-10-03 10:33:31

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

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

这些权限存储在 db 表中。

只是为了向您指出正确的方向:

SHOW GRANTS FOR 'www'@'localhost'

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

What you are selecting are the global privileges.
You are however giving database (and host, but that doesn't matter) specific privileges.

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

These permissions are stored in the db table.

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

陈年往事 2024-10-03 10:33:31

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

SHOW GRANTS FOR 'www'@'localhost'

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

这是 如何在 MySQL 中存储权限 - 我认为事情没有太大变化。

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 stored in MySQL - I don't think things have changed much.

吐个泡泡 2024-10-03 10:33:31

这应该有效:

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

This should work:

GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';
樱桃奶球 2024-10-03 10:33:31

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

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.

挖个坑埋了你 2024-10-03 10:33:31

是的,我同意我创建了 2 个用户并授予他们对数据库的所有权限,但不知怎的,只有一个用户会收到升级的权限,无论我做什么,第二个用户都不会收到权限,尽管我试图授予以与第一个用户完全相同的方式授予用户权限,然后我刷新了权限

Yes I agree I created 2 users and granted them all privileges on the database but somehow only one of the users will receive the upgraded privileges, no matter what I do the second user will not receive the privileges despite the fact that I tried to grant the privileges to the user in exactly the same way that worked with the first user and I flushed the privileges afterwards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文