MySQL grant all privileges to database except one table

前端 未结 4 1521
余生分开走
余生分开走 2020-11-28 08:52

I\'ve been unable to find a reasonable solution to achieve the following:

I wish to have a user that has ALL privileges on a database (or series of databases with th

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 09:05

    I know this is an old post, but I thought I'd add on to @tdammers question for others to see. You can also perform a SELECT CONCAT on information_schema.tables to create your grant commands, and not have to write a separate script.

    First revoke all privileges from that db:

    REVOKE ALL PRIVILEGES ON db.* FROM user@localhost;  
    

    Then create your GRANT statements:

    SELECT CONCAT("GRANT UPDATE ON db.", table_name, " TO user@localhost;")
    FROM information_schema.TABLES
    WHERE table_schema = "YourDB" AND table_name <> "table_to_skip";
    

    Copy and paste the results into your MySQL client and run them all.

提交回复
热议问题