Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7894637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:26:48+00:00 2026-06-03T07:26:48+00:00

Question: How can I give a new user almost all privileges, but still keep

  • 0

Question:

How can I give a new user almost all privileges, but still keep one or more tables/databases protected from them.

Details:

If I have one database,

  • life

And three tables

  • passwords
  • friends
  • hobbies

How do I give this user, for example, the following privileges:

  • INSERT
  • UPDATE
  • DELETE
  • CREATE
  • DROP
  • ALTER

With respect to the first three, I would start with something like so:

GRANT INSERT, UPDATE, DELETE ON life.friends TO username@'localhost' IDENTIFIED BY 'password';
GRANT INSERT, UPDATE, DELETE ON life.hobbies TO username@'localhost' IDENTIFIED BY 'password';

But I am confused as to how to use CREATE and DROP. If I grant drop privileges on the whole database like so:

GRANT DROP ON life TO username@'localhost' IDENTIFIED BY 'password';

Then the user can drop the passwords table, which I do not want. I could instead grant it based on tables like so:

GRANT DROP ON life.friends TO username@'localhost' IDENTIFIED BY 'password';
GRANT DROP ON life.hobbies TO username@'localhost' IDENTIFIED BY 'password';

But then what happens if I grant CREATE privileges like so:

GRANT CREATE ON life TO username@'localhost' IDENTIFIED BY 'password';

Does that mean that the user can not even delete the very tables he/she creates? My question also relates to creating/dropping databases. What if I want to allow the user to create and drop as many of their own databases, but not the life database?

Should I instead change my approach by moving the passwords table into another database?

Thank you in advanced.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:26:49+00:00Added an answer on June 3, 2026 at 7:26 am

    An alternative to @TheScrumMeister’s suggestion of using separate databases would be to define a procedure that wraps CREATE TABLE, but also grants the invoking user the DROP permission on it:

    DELIMITER ;;
    
    CREATE PROCEDURE create_table(
      tbl_name VARCHAR(64) -- maximum length of a table name
    ) BEGIN
      DECLARE EXIT HANDLER FOR SQLEXCEPTION ROLLBACK;
      START TRANSACTION;
        SET @usr = SUBSTRING_INDEX(USER(), '@', 1);  -- invoking username
        SET @tbl = REPLACE(tbl_name, "`", "``");     -- prevent SQL injection
    
        -- just create some dummy table initially - the user can modify it after
        SET @qry = CONCAT("
          CREATE TABLE `", @tbl, "` (
            id INT NOT NULL AUTO_INCREMENT PRIMARY KEY
          );
        ");
        PREPARE stmt FROM  @qry;
        EXECUTE stmt;
        DEALLOCATE PREPARE stmt;
    
        -- now grant DROP to the invoking user but only from localhost
        SET @qry = CONCAT("
          GRANT DROP ON life.`", @tbl, "`
          TO CONCAT(?, \"@'localhost'\") IDENTIFIED BY 'password';
        ");
        PREPARE stmt FROM  @qry;
        EXECUTE stmt USING @usr;
        DEALLOCATE PREPARE stmt;
    
        -- clean up
        SET @qry = NULL;
        SET @usr = NULL;
      COMMIT;
    END;;
    
    DELIMITER ;
    

    To be certain that the user doesn’t create tables any other way, they should not have the CREATE TABLE privilege.

    You could do something similar for databases too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe its a very dumb question but I hope you can give me some
I've been researching my question, rewording it in many ways but I still can't
Title is the entire question. Can someone give me a reason why this happens?
Simple question: Can a swing frame be completely modal ( block all others windows
Here is the question: Can TortoiseSvn work on Windows 2008 without turning off User
This might be a noob question, but can't find an answer anywhere. I have
The code for my question can be located at http://matthewh.me/Scripts/c++/graphs/ . The user name
Sorry if this is too easy of a question, but I'm fairly new to
I was asking a related question but messed the title up and no-one would
Question Can I build a image database/library that has an e-commerce style checkout system

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.