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

Ansible is a configuration management tool that provides you the ability to manage your infrastructure as code. [TODO]

Why manage users/grants as code?

[TODO].