AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 98949
Accepted
Ahmad Abuhasna
Ahmad Abuhasna
Asked: 2015-04-28 04:54:04 +0800 CST2015-04-28 04:54:04 +0800 CST 2015-04-28 04:54:04 +0800 CST

对除一个 mysql 之外的所有数据库授予选择权限

  • 772

我在 MS Windows 2008R2 下test_user创建了一个名为的用户MySQL 5.5.17,我想授予该用户对除 MySQL 数据库之外的所有数据库的选择权限,注意我在这个实例中有大约 200 个数据库。

编辑:

在此处输入图像描述

编辑2:

在此处输入图像描述

mysql mysql-5.5
  • 3 3 个回答
  • 19706 Views

3 个回答

  • Voted
  1. Best Answer
    Jehad Keriaki
    2015-04-28T07:46:32+08:002015-04-28T07:46:32+08:00

    运行以下查询的输出:

    SELECT CONCAT("GRANT SELECT ON ",SCHEMA_NAME,".* TO 'test_user'@'localhost';")
    FROM information_schema.SCHEMATA 
    WHERE SCHEMA_NAME NOT LIKE 'mysql';
    
    • 9
  2. koustuv
    2015-04-28T05:06:09+08:002015-04-28T05:06:09+08:00

    由于您有 200 个数据库并且您不想一一授予。最快的方法是

    GRANT SELECT ON *.* TO 'test_user'@'localhost';
    FLUSH PRIVILEGES;
    

    然后只需撤销 mysql db 中的权限

    REVOKE SELECT ON mysql.* FROM 'test_user'@'localhost' ;
    FLUSH PRIVILEGES;
    

    但是当我在 mysql.* 上选择性地 GRANT 然后 REVOKE 时。然后它正在工作

    在此处输入图像描述

    user@ubuntu:~$ mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 150
    Server version: 5.5.41-0ubuntu0.12.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> CREATE USER 'mysqlrockstar'@'localhost';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> SHOW GRANTS FOR 'mysqlrockstar'@'localhost';
    +---------------------------------------------------+
    | Grants for mysqlrockstar@localhost                |
    +---------------------------------------------------+
    | GRANT USAGE ON *.* TO 'mysqlrockstar'@'localhost' |
    +---------------------------------------------------+
    1 row in set (0.00 sec)
    
    mysql> GRANT SELECT ON mysql.* TO 'mysqlrockstar'@'localhost';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> exit;
    Bye
    user@ubuntu:~$ mysql -u mysqlrockstar
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 151
    Server version: 5.5.41-0ubuntu0.12.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    +--------------------+
    2 rows in set (0.06 sec)
    
    mysql> exit;
    Bye
    user@ubuntu:~$ mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 152
    Server version: 5.5.41-0ubuntu0.12.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> REVOKE SELECT  ON mysql.* FROM 'mysqlrockstar'@'localhost';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> exit;
    Bye
    user@ubuntu:~$ mysql -u mysqlrockstar
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 153
    Server version: 5.5.41-0ubuntu0.12.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    +--------------------+
    1 row in set (0.00 sec)
    
    mysql> use mysql;
    ERROR 1044 (42000): Access denied for user 'mysqlrockstar'@'localhost' to database 'mysql'
    
    • 5
  3. Jelmer Jellema
    2019-01-31T01:29:52+08:002019-01-31T01:29:52+08:00

    多年后,在 MariaDB 中。我所做的:

    • 授予对所有数据库的访问权限
    • 在 mysql 上仅授予“LOCK TABLES”。*

    用户可以看到 mysql,但看不到表。锁定表不起作用,因为 te 用户无法访问任何表。

    • 0

相关问题

  • 是否有任何 MySQL 基准测试工具?[关闭]

  • 我在哪里可以找到mysql慢日志?

  • 如何优化大型数据库的 mysqldump?

  • 什么时候是使用 MariaDB 而不是 MySQL 的合适时机,为什么?

  • 组如何跟踪数据库架构更改?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve