Mysql – How to create thesql user with CREATE USER grant but without access to new databases

MySQLusers

I need mysql admin_user (not root user) which can create write_user with permissions: CREATE, UPDATE, INSERT, DELETE and SELECT.

admin_user and write_user have access to main_db.

write_user will create user_db and only he can access to that db.

If I want that admin_user can create new user with some permissions, admin_user has to be created "WITH GRANT OPTION" but then he has access to all databases.

Question: How to create mysql user with CREATE USER grant but without access to new databases?

Best Answer

With the GRANT command, you can use the ON keyword to set table privileges for users.

For example: GRANT ALL ON user_db to 'write_user'@'localhost'