Search code examples
mysqlshellmariadbprivileges

MYSQL How to grant all privileges to user only to the databases which he created?


im creating a few users: user1 user2 user3 i want to give them ALL PRIVILEGES to the bases(creating/removing) inside their account i want them to see and affect databases only inside their account... how should i do this with shell ?


Solution

  • Do you allow users to run CREATE DATABASE ...?

    Don't allow a user to run that SQL. Instead, provide a STORED PROCEDURE to create the database for him and provide permissions to him. The trick is to be root when you define the SP and use SQL SECURITY DEFINER. And have GRANT ALL PRIVILEGES ON dbname.* TO user@... (with the pieces suitably filled in).