Chef has official support to managing users and grants through a community maintained module. Click here for documentation. There's more modules to manage different aspects of Mysql, you can definitely do a lot more as code using Chef. Make sure to read the documentation to know all the features, know every input option and all the use cases supported.

Create a user

mysql_user 'disenfranchised' do password 'super_secret' action :create end

Drop a user

mysql_user 'foo_user' do action :drop end

Grant SELECT, UPDATE, INSERT permissions to user

mysql_user 'foo_user' do password 'super_secret' database_name 'foo' host '%' privileges [:select,:update,:insert] action :grant end

Grant ALL permissions to user

mysql_user 'foo_user' do password 'super_secret' database_name 'foo' host '%' privileges [:all] action :grant end

Why Chef for managing Mysql users/grants

Chef is a Configuration Management tool used to manage the configuration of software applications and devices. It enables you to define the desired state of your systems and then automatically ensures that they are brought into that state. Chef can be used to manage both physical and virtual machines, as well as cloud instances.