Let MySQL users create databases, but allow access to only their own databases

后端 未结 4 1506
一向
一向 2020-11-29 23:09

I want to have multiple a MySQL users to be able to issue commands like

CREATE DATABASE dbTest;

But I also want each of t

4条回答
  •  情歌与酒
    2020-11-29 23:19

    Create a stored procedure that is defined by the admin user and invokes with the admin user privileges by using SQL SECURITY DEFINER. In the stored procedure,

    • Create the database.
    • Set the privileges on the database so only the current user has access.
    • Execute FLUSH PRIVILEGES to reload the privileges from the grant tables.

    Use USER() to get the current user login details.

    Find out more about SQL SECURITY DEFINER.

提交回复
热议问题