Mysql : user with privileges to create databases, users and grant all privileges on those dbs to users

MySQL

Is it possible in mysql to create user who is able to create database, user and grant all privileges on this database to that user?I dont want to use root user in script

Best Answer

There is nothing special about "root".

CREATE USER foo@localhost ...;   -- establish the existence and pwd of the user
GRANT CREATE DATABASE     -- so foo can do CREATE DATABASE
      ...                 -- and other things (as needed)
    ON *.*                -- probably have to give permission at this level
    TO foo@localhost      -- the user
    WITH GRANT OPTION;    -- so foo can do GRANTs

See also SUPER -- decide whether or not you want this non-user to have all the privileges it entails.

For security reasons, only @localhost should be used with WITH GRANT OPTION.