2013-09-13 19:13:49 +02:00
#MySQL
2012-03-15 06:58:25 +01:00
2013-09-13 19:13:49 +02:00
####Table of Contents
2012-03-17 05:20:02 +01:00
2013-09-13 19:13:49 +02:00
1. [Overview ](#overview )
2. [Module Description - What the module does and why it is useful ](#module-description )
2014-07-10 19:54:35 +02:00
3. [Backwards compatibility information ](#backwards-compatibility )
2013-09-13 19:13:49 +02:00
3. [Setup - The basics of getting started with mysql ](#setup )
* [What mysql affects ](#what-mysql-affects )
* [Beginning with mysql ](#beginning-with-mysql )
4. [Usage - Configuration options and additional functionality ](#usage )
5. [Reference - An under-the-hood peek at what the module is doing and how ](#reference )
5. [Limitations - OS compatibility, etc. ](#limitations )
6. [Development - Guide for contributing to the module ](#development )
2012-03-17 05:20:02 +01:00
2013-09-13 19:13:49 +02:00
##Overview
2012-02-09 20:26:00 +01:00
2014-01-08 22:48:19 +01:00
The mysql module installs, configures, and manages the MySQL service.
2012-02-10 08:15:06 +01:00
2013-09-13 19:13:49 +02:00
##Module Description
2012-02-10 08:15:06 +01:00
2014-01-08 22:48:19 +01:00
The mysql module manages both the installation and configuration of MySQL as
2013-12-27 09:48:27 +01:00
well as extends Puppet to allow management of MySQL resources, such as
2013-09-13 19:13:49 +02:00
databases, users, and grants.
2012-02-09 20:26:00 +01:00
2013-09-17 00:17:16 +02:00
##Backwards Compatibility
2014-01-08 22:48:19 +01:00
This module has just undergone a very large rewrite. Some new classes have been added, and many previous classes and configurations work differently than before. We've attempted to handle backwards compatibility automatically by adding a
2013-09-17 00:17:16 +02:00
`attempt_compatibility_mode` parameter to the main mysql class. If you set
2014-01-08 22:48:19 +01:00
this to 'true' it will attempt to map your previous parameters into the new
2013-10-09 19:37:38 +02:00
`mysql::server` class.
2013-09-17 00:17:16 +02:00
2014-01-08 22:48:19 +01:00
#####WARNING
2013-09-17 00:17:16 +02:00
2014-01-08 22:48:19 +01:00
Compatibility mode may fail. It may eat your MySQL server. PLEASE test it before running it live, even if the test is just a no-op and manual comparison. Please be careful!
2013-09-17 00:17:16 +02:00
2013-09-13 19:13:49 +02:00
##Setup
2012-02-10 08:15:06 +01:00
2013-09-13 19:13:49 +02:00
###What MySQL affects
2012-04-24 06:48:32 +02:00
2014-01-08 22:48:19 +01:00
* MySQL package
* MySQL configuration files
* MySQL service
2013-05-03 18:17:19 +02:00
2013-09-13 19:13:49 +02:00
###Beginning with MySQL
2013-05-03 18:17:19 +02:00
2014-01-08 22:48:19 +01:00
If you just want a server installed with the default options you can run
`include '::mysql::server'` .
If you need to customize options, such as the root
password or `/etc/my.cnf` settings, then you must also pass in an override hash:
2013-05-03 18:17:19 +02:00
2013-09-13 19:13:49 +02:00
```puppet
2013-09-25 00:04:29 +02:00
class { '::mysql::server':
2013-10-27 20:10:12 +01:00
root_password => 'strongpassword',
2014-04-19 01:08:14 +02:00
override_options => $override_options
2013-09-13 19:13:49 +02:00
}
```
2014-04-19 01:08:14 +02:00
(see 'Overrides' below for examples of the hash structure for `$override_options` )
2013-03-03 07:28:10 +01:00
2013-09-13 19:13:49 +02:00
##Usage
2012-04-24 06:48:32 +02:00
2013-10-09 19:37:38 +02:00
All interaction for the server is done via `mysql::server` . To install the
client you use `mysql::client` , and to install bindings you can use
`mysql::bindings` .
2012-02-09 20:26:00 +01:00
2013-09-25 00:04:29 +02:00
###Overrides
2012-02-10 08:15:06 +01:00
2013-10-09 19:37:38 +02:00
The hash structure for overrides in `mysql::server` is as follows:
2012-02-10 08:15:06 +01:00
2013-09-13 19:13:49 +02:00
```puppet
2013-11-11 15:56:16 +01:00
$override_options = {
2013-09-13 19:13:49 +02:00
'section' => {
2014-04-19 01:08:14 +02:00
'item' => 'thing',
2013-09-13 19:13:49 +02:00
}
}
```
2012-02-09 20:26:00 +01:00
2013-09-13 19:13:49 +02:00
For items that you would traditionally represent as:
2013-10-09 19:37:38 +02:00
< pre >
2013-09-13 19:13:49 +02:00
[section]
2014-01-08 22:48:19 +01:00
thing = X
2013-10-09 19:37:38 +02:00
< / pre >
2013-09-13 19:13:49 +02:00
2014-01-24 01:55:48 +01:00
You can just make an entry like `thing => true` , `thing => value` , or `thing => "` in the hash. You can also pass an array `thing => ['value', 'value2']` or even list each `thing => value` separately on separate lines. MySQL doesn't care if 'thing' is alone or set to a value; it'll happily accept both. To keep an option out of the my.cnf file, e.g. when using override_options to revert to a default value, you can pass thing => undef.
2014-01-08 22:48:19 +01:00
If an option needs multiple instances, you can pass an array. For example
2013-12-16 20:00:57 +01:00
```puppet
$override_options = {
'mysqld' => {
'replicate-do-db' => ['base1', 'base2'],
}
}
```
2014-01-08 22:48:19 +01:00
will produce
2013-12-16 20:00:57 +01:00
< pre >
[mysql]
replicate-do-db = base1
replicate-do-db = base2
< / pre >
2013-09-17 00:17:16 +02:00
###Custom configuration
2014-01-08 22:48:19 +01:00
To add custom MySQL configuration, drop additional files into
2014-06-04 14:05:39 +02:00
`includedir` . Dropping files into `includedir` allows you to override settings or add additional ones, which is helpful if you choose not to use `override_options` in `mysql::server` . The `includedir` location is by default set to /etc/mysql/conf.d.
2013-09-17 00:17:16 +02:00
2013-09-13 19:13:49 +02:00
##Reference
###Classes
####Public classes
2013-10-09 19:37:38 +02:00
* `mysql::server` : Installs and configures MySQL.
* `mysql::server::account_security` : Deletes default MySQL accounts.
* `mysql::server::monitor` : Sets up a monitoring user.
* `mysql::server::mysqltuner` : Installs MySQL tuner script.
* `mysql::server::backup` : Sets up MySQL backups via cron.
* `mysql::bindings` : Installs various MySQL language bindings.
* `mysql::client` : Installs MySQL client (for non-servers).
2013-09-13 19:13:49 +02:00
####Private classes
2013-10-09 19:37:38 +02:00
* `mysql::server::install` : Installs packages.
* `mysql::server::config` : Configures MYSQL.
* `mysql::server::service` : Manages service.
* `mysql::server::root_password` : Sets MySQL root password.
2013-11-11 15:56:16 +01:00
* `mysql::server::providers` : Creates users, grants, and databases.
2013-10-09 19:37:38 +02:00
* `mysql::bindings::java` : Installs Java bindings.
* `mysql::bindings::perl` : Installs Perl bindings.
2014-08-13 19:02:14 +02:00
* `mysql::bindings::php` : Installs PHP bindings.
2013-10-09 19:37:38 +02:00
* `mysql::bindings::python` : Installs Python bindings.
* `mysql::bindings::ruby` : Installs Ruby bindings.
* `mysql::client::install` : Installs MySQL client.
2013-09-13 19:13:49 +02:00
###Parameters
2013-09-25 00:04:29 +02:00
####mysql::server
#####`root_password`
2014-01-08 22:48:19 +01:00
The MySQL root password. Puppet will attempt to set the root password and update `/root/.my.cnf` with it.
2013-09-25 00:04:29 +02:00
#####`old_root_password`
2014-01-08 22:48:19 +01:00
The previous root password (**REQUIRED** if you wish to change the root password via Puppet.)
2013-09-13 19:13:49 +02:00
#####`override_options`
2014-01-08 22:48:19 +01:00
The hash of override options to pass into MySQL. It can be structured
like a hash in the my.cnf file, so entries look like
2013-09-13 19:13:49 +02:00
2013-10-09 19:37:38 +02:00
```puppet
2013-11-11 15:56:16 +01:00
$override_options = {
2013-10-09 19:37:38 +02:00
'section' => {
'item' => 'thing',
}
}
```
2013-09-13 19:13:49 +02:00
For items that you would traditionally represent as:
2013-10-09 19:37:38 +02:00
< pre >
2013-09-13 19:13:49 +02:00
[section]
2014-01-08 22:48:19 +01:00
thing = X
2013-10-09 19:37:38 +02:00
< / pre >
2013-09-13 19:13:49 +02:00
2014-01-24 01:55:48 +01:00
You can just make an entry like `thing => true` , `thing => value` , or `thing => "` in the hash. You can also pass an array `thing => ['value', 'value2']` or even list each `thing => value` separately on separate lines. MySQL doesn't care if 'thing' is alone or set to a value; it'll happily accept both. To keep an option out of the my.cnf file, e.g. when using override_options to revert to a default value, you can pass thing => undef.
2013-09-13 19:13:49 +02:00
#####`config_file`
The location of the MySQL configuration file.
#####`manage_config_file`
2014-01-08 22:48:19 +01:00
Whether the MySQL configuration file should be managed.
2013-09-13 19:13:49 +02:00
2014-06-04 14:05:39 +02:00
#####`includedir`
The location of !includedir for custom configuration overrides.
2014-10-29 20:59:59 +01:00
#####`install_options`
Pass install_options array to managed package resources. You must be sure to pass the appropriate options for the correct package manager.
2013-09-13 19:13:49 +02:00
#####`purge_conf_dir`
2014-06-04 14:05:39 +02:00
Whether the `includedir` directory should be purged.
2013-09-13 19:13:49 +02:00
#####`restart`
2014-01-08 22:48:19 +01:00
Whether the service should be restarted when things change.
2013-09-13 19:13:49 +02:00
#####`root_group`
What is the group used for root?
#####`package_ensure`
2014-01-08 23:44:03 +01:00
What to set the package to. Can be 'present', 'absent', or 'x.y.z'.
2013-09-13 19:13:49 +02:00
#####`package_name`
2014-01-08 22:48:19 +01:00
The name of the mysql server package to install.
2013-09-13 19:13:49 +02:00
#####`remove_default_accounts`
Boolean to decide if we should automatically include
2013-10-09 19:37:38 +02:00
`mysql::server::account_security` .
2013-09-13 19:13:49 +02:00
#####`service_enabled`
Boolean to decide if the service should be enabled.
#####`service_manage`
Boolean to decide if the service should be managed.
#####`service_name`
2014-01-08 22:48:19 +01:00
The name of the mysql server service.
2013-09-13 19:13:49 +02:00
#####`service_provider`
2014-01-08 22:48:19 +01:00
The provider to use to manage the service.
2013-09-13 19:13:49 +02:00
2013-11-11 15:56:16 +01:00
#####`users`
2014-01-08 22:48:19 +01:00
Optional hash of users to create, which are passed to [mysql_user ](#mysql_user ).
2014-04-19 01:08:14 +02:00
```
users => {
2013-11-11 15:56:16 +01:00
'someuser@localhost' => {
ensure => 'present',
max_connections_per_hour => '0',
max_queries_per_hour => '0',
max_updates_per_hour => '0',
max_user_connections => '0',
password_hash => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF',
},
}
```
#####`grants`
2014-01-08 22:48:19 +01:00
Optional hash of grants, which are passed to [mysql_grant ](#mysql_grant ).
2014-04-19 01:08:14 +02:00
```
grants => {
2013-11-11 15:59:40 +01:00
'someuser@localhost/somedb.*' => {
2013-11-11 15:56:16 +01:00
ensure => 'present',
options => ['GRANT'],
privileges => ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
table => 'somedb.*',
user => 'someuser@localhost',
},
}
```
#####`databases`
2014-01-08 22:48:19 +01:00
Optional hash of databases to create, which are passed to [mysql_database ](#mysql_database ).
2014-04-19 01:08:14 +02:00
```
databases => {
2013-11-11 15:56:16 +01:00
'somedb' => {
ensure => 'present',
charset => 'utf8',
},
}
```
2013-09-13 19:13:49 +02:00
####mysql::server::backup
#####`backupuser`
2014-01-08 22:48:19 +01:00
MySQL user to create for backups.
2013-09-13 19:13:49 +02:00
#####`backuppassword`
MySQL user password for backups.
#####`backupdir`
2014-01-08 22:48:19 +01:00
Directory to back up into.
2013-09-13 19:13:49 +02:00
2013-11-13 19:33:13 +01:00
#####`backupdirmode`
Permissions applied to the backup directory. This parameter is passed directly
to the `file` resource.
#####`backupdirowner`
Owner for the backup directory. This parameter is passed directly to the `file`
resource.
#####`backupdirgroup`
Group owner for the backup directory. This parameter is passed directly to the
`file` resource.
2013-09-13 19:13:49 +02:00
#####`backupcompress`
Boolean to determine if backups should be compressed.
#####`backuprotate`
How many days to keep backups for.
#####`delete_before_dump`
Boolean to determine if you should cleanup before backing up or after.
#####`backupdatabases`
2014-01-08 22:48:19 +01:00
Array of databases to specifically back up.
2013-09-13 19:13:49 +02:00
#####`file_per_database`
2014-01-08 22:48:19 +01:00
Whether a separate file be used per database.
2013-09-13 19:13:49 +02:00
#####`ensure`
2014-01-08 22:48:19 +01:00
Allows you to remove the backup scripts. Can be 'present' or 'absent'.
2013-09-13 19:13:49 +02:00
2014-02-20 17:17:41 +01:00
#####`execpath`
Allows you to set a custom PATH should your mysql installation be non-standard places. Defaults to `/usr/bin:/usr/sbin:/bin:/sbin`
2013-09-13 19:13:49 +02:00
#####`time`
2014-01-08 22:48:19 +01:00
An array of two elements to set the backup time. Allows ['23', '5'] or ['3', '45'] for HH:MM times.
2012-02-10 08:15:06 +01:00
2014-02-06 16:44:07 +01:00
#####`postscript`
A script that is executed at when the backup is finished. This could be used to (r)sync the backup to a central store. This script can be either a single line that is directly executed or a number of lines, when supplied as an array. It could also be one or more externally managed (executable) files.
2013-09-13 19:13:49 +02:00
####mysql::server::monitor
#####`mysql_monitor_username`
The username to create for MySQL monitoring.
#####`mysql_monitor_password`
The password to create for MySQL monitoring.
#####`mysql_monitor_hostname`
The hostname to allow to access the MySQL monitoring user.
2014-12-16 00:02:19 +01:00
####mysql::server::mysqltuner
***Note***
If using this class on a non-network-connected system you must download the mysqltuner.pl script and have it hosted somewhere accessible via `http(s)://` , `puppet://` , `ftp://` , or a fully qualified file path.
#####`ensure`
Whether the file should be `present` or `absent` . Defaults to `present` .
#####`version`
The version to install from the major/MySQLTuner-perl github repository. Must be a valid tag. Defaults to 'v1.3.0'.
#####`source`
Parameter to optionally specify the source. If not specified, defaults to `https://github.com/major/MySQLTuner-perl/raw/${version}/mysqltuner.pl`
2013-09-13 19:13:49 +02:00
####mysql::bindings
2014-10-29 20:59:59 +01:00
#####`install_options`
Pass install_options array to managed package resources. You must be sure to pass the appropriate options for the correct package manager.
2013-09-13 19:13:49 +02:00
#####`java_enable`
Boolean to decide if the Java bindings should be installed.
#####`perl_enable`
Boolean to decide if the Perl bindings should be installed.
#####`php_enable`
Boolean to decide if the PHP bindings should be installed.
#####`python_enable`
Boolean to decide if the Python bindings should be installed.
#####`ruby_enable`
Boolean to decide if the Ruby bindings should be installed.
#####`java_package_ensure`
2014-01-08 23:44:03 +01:00
What to set the package to. Can be 'present', 'absent', or 'x.y.z'.
2013-09-13 19:13:49 +02:00
#####`java_package_name`
The name of the package to install.
#####`java_package_provider`
What provider should be used to install the package.
#####`perl_package_ensure`
2014-01-08 23:44:03 +01:00
What to set the package to. Can be 'present', 'absent', or 'x.y.z'.
2013-09-13 19:13:49 +02:00
#####`perl_package_name`
The name of the package to install.
#####`perl_package_provider`
What provider should be used to install the package.
#####`python_package_ensure`
2014-01-08 23:44:03 +01:00
What to set the package to. Can be 'present', 'absent', or 'x.y.z'.
2013-09-13 19:13:49 +02:00
#####`python_package_name`
The name of the package to install.
#####`python_package_provider`
What provider should be used to install the package.
#####`ruby_package_ensure`
2014-01-08 23:44:03 +01:00
What to set the package to. Can be 'present', 'absent', or 'x.y.z'.
2013-09-13 19:13:49 +02:00
#####`ruby_package_name`
The name of the package to install.
#####`ruby_package_provider`
What provider should be used to install the package.
####mysql::client
#####`bindings_enable`
Boolean to automatically install all bindings.
2014-10-29 20:59:59 +01:00
#####`install_options`
Pass install_options array to managed package resources. You must be sure to pass the appropriate options for the correct package manager.
2013-10-09 19:37:38 +02:00
#####`package_ensure`
2014-01-08 23:44:03 +01:00
What to set the package to. Can be 'present', 'absent', or 'x.y.z'.
2013-10-09 19:37:38 +02:00
#####`package_name`
What is the name of the mysql client package to install.
2013-09-13 19:13:49 +02:00
###Defines
####mysql::db
2012-02-10 08:15:06 +01:00
2014-01-08 22:48:19 +01:00
Creates a database with a user and assigns some privileges.
2012-02-10 08:15:06 +01:00
2013-09-13 19:13:49 +02:00
```puppet
2012-02-09 20:26:00 +01:00
mysql::db { 'mydb':
user => 'myuser',
password => 'mypass',
host => 'localhost',
2013-09-13 19:13:49 +02:00
grant => ['SELECT', 'UPDATE'],
2012-02-09 20:26:00 +01:00
}
2013-09-13 19:13:49 +02:00
```
2012-02-10 08:15:06 +01:00
2014-03-07 08:08:09 +01:00
Or using a different resource name with exported resources,
```puppet
@@mysql::db { "mydb_${fqdn}":
user => 'myuser',
password => 'mypass',
dbname => 'mydb',
host => ${fqdn},
grant => ['SELECT', 'UPDATE'],
tag => $domain,
}
```
Then collect it on the remote DB server.
```puppet
Mysql::Db < < | tag == $domain |>>
```
2014-01-28 23:31:14 +01:00
If you set the sql param to a file when creating a database,
the file gets imported into the new database.
For large sql files you should raise the $import_timeout parameter,
set by default to 300 seconds
```puppet
mysql::db { 'mydb':
user => 'myuser',
password => 'mypass',
host => 'localhost',
grant => ['SELECT', 'UPDATE'],
sql => '/path/to/sqlfile',
import_timeout => 900,
}
```
2013-09-13 19:13:49 +02:00
###Providers
2012-04-24 07:53:59 +02:00
2013-09-13 19:13:49 +02:00
####mysql_database
2012-04-24 07:53:59 +02:00
2014-01-08 22:48:19 +01:00
`mysql_database` can be used to create and manage databases within MySQL.
2012-02-09 20:26:00 +01:00
2013-09-13 19:13:49 +02:00
```puppet
mysql_database { 'information_schema':
ensure => 'present',
charset => 'utf8',
collate => 'utf8_swedish_ci',
}
mysql_database { 'mysql':
ensure => 'present',
charset => 'latin1',
collate => 'latin1_swedish_ci',
}
```
2012-02-09 20:26:00 +01:00
2013-09-13 19:13:49 +02:00
####mysql_user
2012-02-09 20:26:00 +01:00
2014-01-08 22:48:19 +01:00
`mysql_user` can be used to create and manage user grants within MySQL.
2012-02-09 20:26:00 +01:00
2013-09-13 19:13:49 +02:00
```puppet
mysql_user { 'root@127.0.0.1':
ensure => 'present',
max_connections_per_hour => '0',
max_queries_per_hour => '0',
max_updates_per_hour => '0',
max_user_connections => '0',
}
```
2012-02-09 20:26:00 +01:00
2013-09-13 19:13:49 +02:00
####mysql_grant
2012-02-09 20:26:00 +01:00
2014-01-08 22:48:19 +01:00
`mysql_grant` can be used to create grant permissions to access databases within
2013-09-13 19:13:49 +02:00
MySQL. To use it you must create the title of the resource as shown below,
following the pattern of `username@hostname/database.table` :
```puppet
mysql_grant { 'root@localhost/*.*':
ensure => 'present',
options => ['GRANT'],
privileges => ['ALL'],
table => '*.*',
user => 'root@localhost',
}
```
2014-09-15 18:11:46 +02:00
It is possible to specify privileges down to the column level:
```puppet
mysql_grant { 'root@localhost/mysql.user':
ensure => 'present',
privileges => ['SELECT (Host, User)'],
table => 'mysql.user',
user => 'root@localhost',
}
```
2013-09-13 19:13:49 +02:00
##Limitations
This module has been tested on:
* RedHat Enterprise Linux 5/6
* Debian 6/7
* CentOS 5/6
* Ubuntu 12.04
Testing on other platforms has been light and cannot be guaranteed.
#Development
Puppet Labs modules on the Puppet Forge are open projects, and community
contributions are essential for keeping them great. We can’ t access the
huge number of platforms and myriad of hardware, software, and deployment
configurations that Puppet is intended to serve.
We want to keep it as easy as possible to contribute changes so that our
modules work in your environment. There are a few guidelines that we need
contributors to follow so that we can have a chance of keeping on top of things.
You can read the complete module contribution guide [on the Puppet Labs wiki. ](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing )
### Authors
2013-12-27 23:30:34 +01:00
This module is based on work by David Schmitt. The following contributors have contributed patches to this module (beyond Puppet Labs):
2013-09-13 19:13:49 +02:00
* Larry Ludwig
* Christian G. Warden
* Daniel Black
* Justin Ellison
* Lowe Schmidt
* Matthias Pigulla
* William Van Hevelingen
* Michael Arnold
* Chris Weyl
2012-02-09 20:26:00 +01:00