← Back to the SQL generator

Manage MySQL users & grants with Puppet

Puppet manages users and privileges through the official puppetlabs-mysql module, which provides the mysql::db defined type and mysql_user / mysql_grant resources. It can manage much more than users, so read the docs for every option.

Create a user with SELECT and UPDATE privileges

mysql::db { 'mydb':
  user     => 'myuser',
  password => 'mypass',
  host     => 'localhost',
  grant    => ['SELECT', 'UPDATE'],
}

Use a pre-hashed password

Avoid committing plaintext by supplying an already-hashed password:

mysql::db { 'mydb':
  user     => 'myuser',
  password => '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4',
  host     => 'localhost',
  grant    => ['SELECT', 'UPDATE'],
}

Why Puppet for MySQL users & grants?

Puppet is a declarative configuration-management tool: you describe the desired state and Puppet's agent continuously enforces it. Key benefits for managing database access include:

Store secrets with Hiera + eyaml rather than in plain manifests.

Generate the raw SQL instead →