File: README.md

package info (click to toggle)
puppet-module-puppetlabs-mysql 5.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 872 kB
  • sloc: ruby: 4,258; sh: 26; makefile: 5
file content (1329 lines) | stat: -rw-r--r-- 35,929 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
# mysql

#### Table of Contents

1. [Module Description - What the module does and why it is useful](#module-description)
2. [Setup - The basics of getting started with mysql](#setup)
    * [Beginning with mysql](#beginning-with-mysql)
3. [Usage - Configuration options and additional functionality](#usage)
    * [Customize server options](#customize-server-options)
    * [Create a database](#create-a-database)
    * [Customize configuration](#customize-configuration)
    * [Work with an existing server](#work-with-an-existing-server)
    * [Specify passwords](#specify-passwords)
    * [Install Percona server on CentOS](#install-percona-server-on-centos)
    * [Install MariaDB on Ubuntu](#install-mariadb-on-ubuntu)
4. [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)

## Module Description

The mysql module installs, configures, and manages the MySQL service.

This module manages both the installation and configuration of MySQL, as well as extending Puppet to allow management of MySQL resources, such as databases, users, and grants.

## Setup

### Beginning with mysql

To install a server with the default options:

`include '::mysql::server'`.

To customize options, such as the root password or `/etc/my.cnf` settings, you must also pass in an override hash:

```puppet
class { '::mysql::server':
  root_password           => 'strongpassword',
  remove_default_accounts => true,
  override_options        => $override_options
}
```

See [**Customize Server Options**](#customize-server-options) below for examples of the hash structure for $override_options.

## Usage

All interaction for the server is done via `mysql::server`. To install the client, use `mysql::client`. To install bindings, use `mysql::bindings`.

### Customize server options

To define server options, structure a hash structure of overrides in `mysql::server`. This hash resembles a hash in the my.cnf file:

```puppet
$override_options = {
  'section' => {
    'item' => 'thing',
  }
}
```

For options that you would traditionally represent in this format:

```
[section]
thing = X
```

Entries can be created as `thing => true`, `thing => value`, or `thing => ""` in the hash. Alternatively, you can pass an array as `thing => ['value', 'value2']` or list each `thing => value` separately on individual lines.

You can pass a variable in the hash without setting a value for it; the variable would then use MySQL's default settings. To exclude an option from the `my.cnf` file --- for example, when using `override_options` to revert to a default value --- pass `thing => undef`.

If an option needs multiple instances, pass an array. For example,

```puppet
$override_options = {
  'mysqld' => {
    'replicate-do-db' => ['base1', 'base2'],
  }
}
```

produces

```puppet
[mysqld]
replicate-do-db = base1
replicate-do-db = base2
```

To implement version specific parameters, specify the version, such as [mysqld-5.5]. This allows one config for different versions of MySQL.

### Create a database

To create a database with a user and some assigned privileges:

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

To use 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 you can collect it on the remote DB server:

```puppet
Mysql::Db <<| tag == $domain |>>
```

If you set the sql parameter to a file when creating a database, the file is imported into the new database.

For large sql files, increase the `import_timeout` parameter, which defaults to 300 seconds.

```puppet
mysql::db { 'mydb':
  user     => 'myuser',
  password => 'mypass',
  host     => 'localhost',
  grant    => ['SELECT', 'UPDATE'],
  sql      => '/path/to/sqlfile.gz',
  import_cat_cmd => 'zcat',
  import_timeout => 900,
}
```

### Customize configuration

To add custom MySQL configuration, place additional files into `includedir`. This allows you to override settings or add additional ones, which is helpful if you don't use `override_options` in `mysql::server`. The `includedir` location is by default set to `/etc/mysql/conf.d`.

### Work with an existing server

To instantiate databases and users on an existing MySQL server, you need a `.my.cnf` file in `root`'s home directory. This file must specify the remote server address and credentials. For example:

```puppet
[client]
user=root
host=localhost
password=secret
```

This module uses the `mysqld_version` fact to discover the server version being used.  By default, this is set to the output of `mysqld -V`.  If you're working with a remote MySQL server, you may need to set a custom fact for `mysqld_version` to ensure correct behaviour.

When working with a remote server, do *not* use the `mysql::server` class in your Puppet manifests.

### Specify passwords

In addition to passing passwords as plain text, you can input them as hashes. For example:

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

### Install Percona server on CentOS

This example shows how to do a minimal installation of a Percona server on a
CentOS system. This sets up the Percona server, client, and bindings (including Perl and Python bindings). You can customize this usage and update the version as needed.

This usage has been tested on Puppet 4.4 / CentOS 7 / Percona Server 5.7.

**Note:** The installation of the yum repository is not part of this package
and is here only to show a full example of how you can install.

```puppet
yumrepo { 'percona':
  descr    => 'CentOS $releasever - Percona',
  baseurl  => 'http://repo.percona.com/centos/$releasever/os/$basearch/',
  gpgkey   => 'http://www.percona.com/downloads/percona-release/RPM-GPG-KEY-percona',
  enabled  => 1,
  gpgcheck => 1,
}

class {'mysql::server':
  package_name     => 'Percona-Server-server-57',
  package_ensure   => '5.7.11-4.1.el7',
  service_name     => 'mysql',
  config_file      => '/etc/my.cnf',
  includedir       => '/etc/my.cnf.d',
  root_password    => 'PutYourOwnPwdHere',
  override_options => {
    mysqld => {
      log-error => '/var/log/mysqld.log',
      pid-file  => '/var/run/mysqld/mysqld.pid',
    },
    mysqld_safe => {
      log-error => '/var/log/mysqld.log',
    },
  }
}

# Note: Installing Percona-Server-server-57 also installs Percona-Server-client-57.
# This shows how to install the Percona MySQL client on its own
class {'mysql::client':
  package_name   => 'Percona-Server-client-57',
  package_ensure => '5.7.11-4.1.el7',
}

# These packages are normally installed along with Percona-Server-server-57
# If you needed to install the bindings, however, you could do so with this code
class { 'mysql::bindings':
  client_dev_package_name   => 'Percona-Server-shared-57',
  client_dev_package_ensure => '5.7.11-4.1.el7',
  client_dev                => true,
  daemon_dev_package_name   => 'Percona-Server-devel-57',
  daemon_dev_package_ensure => '5.7.11-4.1.el7',
  daemon_dev                => true,
  perl_enable               => true,
  perl_package_name         => 'perl-DBD-MySQL',
  python_enable             => true,
  python_package_name       => 'MySQL-python',
}

# Dependencies definition
Yumrepo['percona']->
Class['mysql::server']

Yumrepo['percona']->
Class['mysql::client']

Yumrepo['percona']->
Class['mysql::bindings']
```

### Install MariaDB on Ubuntu

#### Optional: Install the MariaDB official repo

In this example, we'll use the latest stable (currently 10.1) from the official MariaDB repository, not the one from the distro repository. You could instead use the package from the Ubuntu repository. Make sure you use the repository corresponding to the version you want.

**Note:** `sfo1.mirrors.digitalocean.com` is one of many mirrors available. You can use any official mirror.

```puppet
include apt

apt::source { 'mariadb':
  location => 'http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.1/ubuntu',
  release  => $::lsbdistcodename,
  repos    => 'main',
  key      => {
    id     => '199369E5404BD5FC7D2FE43BCBCB082A1BB943DB',
    server => 'hkp://keyserver.ubuntu.com:80',
  },
  include => {
    src   => false,
    deb   => true,
  },
}
```

#### Install the MariaDB server

This example shows MariaDB server installation on Ubuntu Trusty. Adjust the version and the parameters of `my.cnf` as needed. All parameters of the `my.cnf` can be defined using the `override_options` parameter.

The folders `/var/log/mysql` and `/var/run/mysqld` are created automatically, but if you are using other custom folders, they should exist as prerequisites for this code.

All the values set here are an example of a working minimal configuration.

Specify the version of the package you want with the `package_ensure` parameter.

```puppet
class {'::mysql::server':
  package_name     => 'mariadb-server',
  package_ensure   => '10.1.14+maria-1~trusty',
  service_name     => 'mysql',
  root_password    => 'AVeryStrongPasswordUShouldEncrypt!',
  override_options => {
    mysqld => {
      'log-error' => '/var/log/mysql/mariadb.log',
      'pid-file'  => '/var/run/mysqld/mysqld.pid',
    },
    mysqld_safe => {
      'log-error' => '/var/log/mysql/mariadb.log',
    },
  }
}

# Dependency management. Only use that part if you are installing the repository
# as shown in the Preliminary step of this example.
Apt::Source['mariadb'] ~>
Class['apt::update'] ->
Class['::mysql::server']

```

#### Install the MariaDB client

This example shows how to install the MariaDB client and all of the bindings at once. You can do this installation separately from the server installation.

Specify the version of the package you want with the `package_ensure` parameter.

```puppet
class {'::mysql::client':
  package_name    => 'mariadb-client',
  package_ensure  => '10.1.14+maria-1~trusty',
  bindings_enable => true,
}

# Dependency management. Only use that part if you are installing the repository as shown in the Preliminary step of this example.
Apt::Source['mariadb'] ~>
Class['apt::update'] ->
Class['::mysql::client']
```

### Install MySQL Community server on CentOS

You can install MySQL Community Server on CentOS using the mysql module and Hiera. This example was tested with the following versions:

* MySQL Community Server 5.6
* Centos 7.3
* Puppet 3.8.7 using Hiera
* puppetlabs-mysql module v3.9.0

In Puppet:

```puppet
include ::mysql::server

create_resources(yumrepo, hiera('yumrepo', {}))

Yumrepo['repo.mysql.com'] -> Anchor['mysql::server::start']
Yumrepo['repo.mysql.com'] -> Package['mysql_client']

create_resources(mysql::db, hiera('mysql::server::db', {}))
```

In Hiera:

```yaml
---

# Centos 7.3
yumrepo:
  'repo.mysql.com':
    baseurl: "http://repo.mysql.com/yum/mysql-5.6-community/el/%{::operatingsystemmajrelease}/$basearch/"
    descr: 'repo.mysql.com'
    enabled: 1
    gpgcheck: true
    gpgkey: 'http://repo.mysql.com/RPM-GPG-KEY-mysql'

mysql::client::package_name: "mysql-community-client" # required for proper MySQL installation
mysql::server::package_name: "mysql-community-server" # required for proper MySQL installation
mysql::server::package_ensure: 'installed' # do not specify version here, unfortunately yum fails with error that package is already installed
mysql::server::root_password: "change_me_i_am_insecure"
mysql::server::manage_config_file: true
mysql::server::service_name: 'mysqld' # required for puppet module
mysql::server::override_options:
  'mysqld':
    'bind-address': '127.0.0.1'
    'log-error': /var/log/mysqld.log' # required for proper MySQL installation
  'mysqld_safe':
    'log-error': '/var/log/mysqld.log'  # required for proper MySQL installation

# create database + account with access, passwords are not encrypted
mysql::server::db:
  "dev":
    user: "dev"
    password: "devpass"
    host: "127.0.0.1"
    grant:
      - "ALL"

```


## Reference

### Classes

#### Public classes

* [`mysql::server`](#mysqlserver): Installs and configures MySQL.
* [`mysql::server::monitor`](#mysqlservermonitor): Sets up a monitoring user.
* [`mysql::server::mysqltuner`](#mysqlservermysqltuner): Installs MySQL tuner script.
* [`mysql::server::backup`](#mysqlserverbackup): Sets up MySQL backups via cron.
* [`mysql::bindings`](#mysqlbindings): Installs various MySQL language bindings.
* [`mysql::client`](#mysqlclient): Installs MySQL client (for non-servers).

#### Private classes

* `mysql::server::install`: Installs packages.
* `mysql::server::installdb`: Implements setup of mysqld data directory (e.g. /var/lib/mysql)
* `mysql::server::config`: Configures MYSQL.
* `mysql::server::service`: Manages service.
* `mysql::server::account_security`: Deletes default MySQL accounts.
* `mysql::server::root_password`: Sets MySQL root password.
* `mysql::server::providers`: Creates users, grants, and databases.
* `mysql::bindings::client_dev`: Installs MySQL client development package.
* `mysql::bindings::daemon_dev`: Installs MySQL daemon development package.
* `mysql::bindings::java`: Installs Java bindings.
* `mysql::bindings::perl`: Installs Perl bindings.
* `mysql::bindings::php`: Installs PHP bindings.
* `mysql::bindings::python`: Installs Python bindings.
* `mysql::bindings::ruby`: Installs Ruby bindings.
* `mysql::client::install`:  Installs MySQL client.
* `mysql::backup::mysqldump`: Implements mysqldump backups.
* `mysql::backup::mysqlbackup`: Implements backups with Oracle MySQL Enterprise Backup.
* `mysql::backup::xtrabackup`: Implements backups with XtraBackup from Percona.

### Parameters

#### mysql::server

##### `create_root_user`

Whether root user should be created.

Valid values are `true`, `false`.

Defaults to `true`.

This is useful for a cluster setup with Galera. The root user has to be created only once. You can set this parameter true on one node and set it to false on the remaining nodes.

#####  `create_root_my_cnf`

Whether to create `/root/.my.cnf`.

Valid values are `true`, `false`.

Defaults to `true`.

`create_root_my_cnf` allows creation of `/root/.my.cnf` independently of `create_root_user`. You can use this for a cluster setup with Galera where you want `/root/.my.cnf` to exist on all nodes.

#####  `root_password`

The MySQL root password. Puppet attempts to set the root password and update `/root/.my.cnf` with it.

This is required if `create_root_user` or `create_root_my_cnf` are true. If `root_password` is 'UNSET', then `create_root_user` and `create_root_my_cnf` are assumed to be false --- that is, the MySQL root user and `/root/.my.cnf` are not created.

Password changes are supported; however, the old password must be set in `/root/.my.cnf`. Effectively, Puppet uses the old password, configured in `/root/my.cnf`, to set the new password in MySQL, and then updates `/root/.my.cnf` with the new password.

##### `old_root_password`

This parameter no longer does anything. It exists only for backwards compatibility. See the `root_password` parameter above for details on changing the root password.

##### `override_options`

Specifies override options to pass into MySQL. Structured like a hash in the my.cnf file:

```puppet
$override_options = {
  'section' => {
    'item'             => 'thing',
  }
}
```

See [**Customize Server Options**](#customize-server-options) above for usage details.

##### `config_file`

The location, as a path, of the MySQL configuration file.

##### `manage_config_file`

Whether the MySQL configuration file should be managed.

Valid values are `true`, `false`.

Defaults to `true`.

##### `includedir`

The location, as a path, of !includedir for custom configuration overrides.

##### `install_options`

Passes [install_options](https://docs.puppetlabs.com/references/latest/type.html#package-attribute-install_options) array to managed package resources. You must pass the appropriate options for the specified package manager.

##### `purge_conf_dir`

Whether the `includedir` directory should be purged.

Valid values are `true`, `false`.

Defaults to `false`.

##### `restart`

Whether the service should be restarted when things change.

Valid values are `true`, `false`.

Defaults to `false`.

##### `root_group`

The name of the group used for root. Can be a group name or a group ID. See more about the [`group` file attribute](https://docs.puppetlabs.com/references/latest/type.html#file-attribute-group).

##### `mysql_group`

The name of the group of the MySQL daemon user. Can be a group name or a group ID. See more about the [`group` file attribute](https://docs.puppetlabs.com/references/latest/type.html#file-attribute-group).

##### `package_ensure`

Whether the package exists or should be a specific version.

Valid values are 'present', 'absent', or 'x.y.z'.

Defaults to 'present'.

##### `package_manage`

Whether to manage the MySQL server package.

Defaults to `true`.

##### `package_name`

The name of the MySQL server package to install.

##### `remove_default_accounts`

Specifies whether to automatically include `mysql::server::account_security`.

Valid values are `true`, `false`.

Defaults to `false`.

##### `service_enabled`

Specifies whether the service should be enabled.

Valid values are `true`, `false`.

Defaults to `true`.

##### `service_manage`

Specifies whether the service should be managed.

Valid values are `true`, `false`.

Defaults to `true`.

##### `service_name`

The name of the MySQL server service.

Defaults are OS dependent, defined in 'params.pp'.

##### `service_provider`

The provider to use to manage the service.

For Ubuntu, defaults to 'upstart'; otherwise, default is undefined.

##### `users`

Optional hash of users to create, which are passed to [mysql_user](#mysql_user).

```puppet
users => {
  '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',
    tls_options              => ['NONE'],
  },
}
```

##### `grants`

Optional hash of grants, which are passed to [mysql_grant](#mysql_grant).

```puppet
grants => {
  'someuser@localhost/somedb.*' => {
    ensure     => 'present',
    options    => ['GRANT'],
    privileges => ['SELECT', 'INSERT', 'UPDATE', 'DELETE'],
    table      => 'somedb.*',
    user       => 'someuser@localhost',
  },
}
```

##### `databases`

Optional hash of databases to create, which are passed to [mysql_database](#mysql_database).

```puppet
databases   => {
  'somedb'  => {
    ensure  => 'present',
    charset => 'utf8',
  },
}
```

#### mysql::server::backup

##### `backupuser`

MySQL user to create for backups.

##### `backuppassword`

MySQL user password for backups.

##### `backupdir`

Directory in which to store backups.

##### `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.

##### `backupcompress`

Whether backups should be compressed.

Valid values are `true`, `false`.

Defaults to `true`.

##### `backuprotate`

How many days to keep backups.

Valid value is an integer.

Defaults to 30.

##### `delete_before_dump`

Whether to delete old .sql files before backing up. Setting to true deletes old files before backing up, while setting to false deletes them after backup.

Valid values are `true`, `false`.

Defaults to `false`.

##### `backupdatabases`

Specifies an array of databases to back up.

##### `file_per_database`

Whether a separate file be used per database.

Valid values are `true`, `false`.

Defaults to `false`.

##### `include_routines`

Whether or not to include routines for each database when doing a `file_per_database` backup.

Defaults to `false`.

##### `include_triggers`

Whether or not to include triggers for each database when doing a `file_per_database` backup.

Defaults to `false`.

##### `ensure`

Allows you to remove the backup scripts.

Valid values are 'present', 'absent'.

Defaults to 'present'.

##### `execpath`

Allows you to set a custom PATH should your MySQL installation be non-standard places. Defaults to `/usr/bin:/usr/sbin:/bin:/sbin`.

##### `time`

An array of two elements to set the backup time. Allows ['23', '5'] (i.e., 23:05) or ['3', '45'] (i.e., 03:45) for HH:MM times.

#### mysql::server::backup

##### `postscript`

A script that is executed when the backup is finished. This could be used to sync the backup to a central store. This script can be either a single line that is directly executed or a number of lines supplied as an array. It could also be one or more externally managed (executable) files.

##### `prescript`

A script that is executed before the backup begins.

##### `provider`

Sets the server backup implementation. Valid values are:

* `mysqldump`: Implements backups with mysqldump. Backup type: Logical. This is the default value.
* `mysqlbackup`: Implements backups with MySQL Enterprise Backup from Oracle. Backup type: Physical. To use this type of backup, you'll need the `meb` package, which is available in RPM and TAR formats from Oracle. For Ubuntu, you can use [meb-deb](https://github.com/dveeden/meb-deb) to create a package from an official tarball.
* `xtrabackup`: Implements backups with XtraBackup from Percona. Backup type: Physical.

##### `maxallowedpacket`

Defines the maximum SQL statement size for the backup dump script. The default value is 1MB, as this is the default MySQL Server value.

##### `optional_args`

Specifies an array of optional arguments which should be passed through to the backup tool. (Currently only supported by the xtrabackup provider.)

#### 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 from which the monitoring user requests are allowed access.

#### mysql::server::mysqltuner

**Note**: If you're 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`

Ensures that the resource exists.

Valid values are 'present', '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'.

##### `environment`

Environment variables active during download, e.g. to download via proxies: environment => 'https_proxy=http://proxy.example.com:80'

#### mysql::bindings

##### `client_dev`

Specifies whether `::mysql::bindings::client_dev` should be included.

Valid values are `true`', `false`.

Defaults to `false`.

##### `daemon_dev`

Specifies whether `::mysql::bindings::daemon_dev` should be included.

Valid values are `true`, `false`.

Defaults to `false`.

##### `java_enable`

Specifies whether `::mysql::bindings::java` should be included.

Valid values are `true`, `false`.

Defaults to `false`.

#####  `perl_enable`

Specifies whether `mysql::bindings::perl` should be included.

Valid values are `true`, `false`.

Defaults to `false`.

##### `php_enable`

Specifies whether `mysql::bindings::php` should be included.

Valid values are `true`, `false`.

Defaults to `false`.

##### `python_enable`

Specifies whether `mysql::bindings::python` should be included.

Valid values are `true`, `false`.

Defaults to `false`.

##### `ruby_enable`

Specifies whether `mysql::bindings::ruby` should be included.

Valid values are `true`, `false`.

Defaults to `false`.

##### `install_options`

Passes `install_options` array to managed package resources. You must pass the [appropriate options](https://docs.puppetlabs.com/references/latest/type.html#package-attribute-install_options) for the package manager(s).

##### `client_dev_package_ensure`

Whether the package should be present, absent, or a specific version.

Valid values are 'present', 'absent', or 'x.y.z'.

Only applies if `client_dev => true`.

##### `client_dev_package_name`

The name of the client_dev package to install.

Only applies if `client_dev => true`.

##### `client_dev_package_provider`

The provider to use to install the client_dev package.

Only applies if `client_dev => true`.

##### `daemon_dev_package_ensure`

Whether the package should be present, absent, or a specific version.

Valid values are 'present', 'absent', or 'x.y.z'.

Only applies if `daemon_dev => true`.

##### `daemon_dev_package_name`

The name of the daemon_dev package to install.

Only applies if `daemon_dev => true`.

##### `daemon_dev_package_provider`

The provider to use to install the daemon_dev package.

Only applies if `daemon_dev => true`.

##### `java_package_ensure`

Whether the package should be present, absent, or a specific version.

Valid values are 'present', 'absent', or 'x.y.z'.

Only applies if `java_enable => true`.

##### `java_package_name`

The name of the Java package to install.

Only applies if `java_enable => true`.

##### `java_package_provider`

The provider to use to install the Java package.

Only applies if `java_enable => true`.

##### `perl_package_ensure`

Whether the package should be present, absent, or a specific version.

Valid values are 'present', 'absent', or 'x.y.z'.

Only applies if `perl_enable => true`.

##### `perl_package_name`

The name of the Perl package to install.

Only applies if `perl_enable => true`.

##### `perl_package_provider`

The provider to use to install the Perl package.

Only applies if `perl_enable => true`.

##### `php_package_ensure`

Whether the package should be present, absent, or a specific version.

Valid values are 'present', 'absent', or 'x.y.z'.

Only applies if `php_enable => true`.

##### `php_package_name`

The name of the PHP package to install.

Only applies if `php_enable => true`.

##### `python_package_ensure`

Whether the package should be present, absent, or a specific version.

Valid values are 'present', 'absent', or 'x.y.z'.

Only applies if `python_enable => true`.

##### `python_package_name`

The name of the Python package to install.

Only applies if `python_enable => true`.

##### `python_package_provider`

The provider to use to install the Python package.

Only applies if `python_enable => true`.

##### `ruby_package_ensure`

Whether the package should be present, absent, or a specific version.

Valid values are 'present', 'absent', or 'x.y.z'.

Only applies if `ruby_enable => true`.

##### `ruby_package_name`

The name of the Ruby package to install.

Only applies if `ruby_enable => true`.

##### `ruby_package_provider`

What provider should be used to install the package.

#### mysql::client

##### `bindings_enable`

Whether to automatically install all bindings.

Valid values are `true`, `false`.

Default to `false`.

##### `install_options`

Array of install options for managed package resources. You must pass the appropriate options for the package manager.

##### `package_ensure`

Whether the MySQL package should be present, absent, or a specific version.

Valid values are 'present', 'absent', or 'x.y.z'.

##### `package_manage`

Whether to manage the MySQL client package.

Defaults to `true`.

##### `package_name`

The name of the MySQL client package to install.

### Defines

#### mysql::db

```puppet
mysql_database { 'information_schema':
  ensure  => 'present',
  charset => 'utf8',
  collate => 'utf8_swedish_ci',
}
mysql_database { 'mysql':
  ensure  => 'present',
  charset => 'latin1',
  collate => 'latin1_swedish_ci',
}
```

##### `user`

The user for the database you're creating.

##### `password`

The password for $user for the database you're creating.

##### `dbname`

The name of the database to create.

Defaults to "$name".

##### `charset`

The character set for the database.

Defaults to 'utf8'.

##### `collate`

The collation for the database.

Defaults to 'utf8_general_ci'.

##### `host`

The host to use as part of user@host for grants.

Defaults to 'localhost'.

##### `grant`

The privileges to be granted for user@host on the database.

Defaults to 'ALL'.

##### `sql`

The path to the sqlfile you want to execute. This can be single file specified as string, or it can be an array of strings.

Defaults to `undef`.

##### `enforce_sql`

Specifies whether executing the sqlfiles should happen on every run. If set to false, sqlfiles only run once.

Valid values are `true`, `false`.

Defaults to `false`.

##### `ensure`

Specifies whether to create the database.

Valid values are 'present', 'absent'.

Defaults to 'present'.

##### `import_timeout`

Timeout, in seconds, for loading the sqlfiles.

Defaults to 300.

##### `import_cat_cmd`

Command to read the sqlfile for importing the database. Useful for compressed sqlfiles. For example, you can use 'zcat' for .gz files.

Defaults to 'cat'.

### Types

#### mysql_database

`mysql_database` creates and manages databases within MySQL.

##### `ensure`

Whether the resource is present.

Valid values are 'present', 'absent'.

Defaults to 'present'.

##### `name`

The name of the MySQL database to manage.

##### `charset`

The CHARACTER SET setting for the database.

Defaults to ':utf8'.

##### `collate`

The COLLATE setting for the database.

Defaults to ':utf8_general_ci'.

#### mysql_user

Creates and manages user grants within MySQL.

```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',
}
```

You can also specify an authentication plugin.

```puppet
mysql_user{ 'myuser'@'localhost':
  ensure                   => 'present',
  plugin                   => 'unix_socket',
}
```

TLS options can be specified for a user.

```puppet
mysql_user{ 'myuser'@'localhost':
  ensure                   => 'present',
  tls_options              => ['SSL'],
}
```

##### `name`

The name of the user, as 'username@hostname' or username@hostname.

##### `password_hash`

The user's password hash of the user. Use mysql_password() for creating such a hash.

##### `max_user_connections`

Maximum concurrent connections for the user.

Must be an integer value.

A value of '0' specifies no (or global) limit.

##### `max_connections_per_hour`

Maximum connections per hour for the user.

Must be an integer value.

A value of '0' specifies no (or global) limit.

##### `max_queries_per_hour`

Maximum queries per hour for the user.

Must be an integer value.

A value of '0' specifies no (or global) limit.

##### `max_updates_per_hour`

Maximum updates per hour for the user.

Must be an integer value.

A value of '0' specifies no (or global) limit.

##### `tls_options`

SSL-related options for a MySQL account, using one or more tls_option values. 'NONE' specifies that the account has no TLS options enforced, and the available options are 'SSL', 'X509', 'CIPHER *cipher*', 'ISSUER *issuer*', 'SUBJECT *subject*'; as stated in the MySQL documentation.


#### mysql_grant

`mysql_grant` creates grant permissions to access databases within MySQL. To create grant permissions to access databases with MySQL, 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',
}
```

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',
}
```

To revoke GRANT privilege specify ['NONE'].

##### `ensure`

Whether the resource is present.

Valid values are 'present', 'absent'.

Defaults to 'present'.

##### `name`

Name to describe the grant. Must in a 'user/table' format.

##### `privileges`

Privileges to grant the user.

##### `table`

The table to which privileges are applied.

##### `user`

User to whom privileges are granted.

##### `options`

MySQL options to grant. Optional.

#### mysql_plugin

`mysql_plugin` can be used to load plugins into the MySQL Server.

```puppet
mysql_plugin { 'auth_socket':
  ensure     => 'present',
  soname     => 'auth_socket.so',
}
```

##### `ensure`

Whether the resource is present.

Valid values are 'present', 'absent'.

Defaults to 'present'.

##### `name`

The name of the MySQL plugin to manage.

#####  `soname`

The library file name.

#### `mysql_datadir`

Initializes the MySQL data directory with version specific code. Pre MySQL 5.7.6 it uses mysql_install_db. After MySQL 5.7.6 it uses mysqld --initialize-insecure.

Insecure initialization is needed, as mysqld version 5.7 introduced 'secure by default' mode. This means MySQL generates a random password and writes it to STDOUT. This means puppet can never access the database server afterwards, as no credentials are available.

This type is an internal type and should not be called directly.

### Facts

#### `mysql_version`

Determines the MySQL version by parsing the output from `mysql --version`

#### `mysql_server_id`

Generates a unique id, based on the node's MAC address, which can be used as `server_id`. This fact will *always* return `0` on nodes that have only loopback interfaces. Because those nodes aren't connected to the outside world, this shouldn't cause any conflicts.

### Tasks

The MySQL module has an example task that allows a user to execute arbitary SQL against a database. Please refer to to the [PE documentation](https://puppet.com/docs/pe/2017.3/orchestrator/running_tasks.html) or [Bolt documentation](https://puppet.com/docs/bolt/latest/bolt.html) on how to execute a task.

## Limitations

This module has been tested on:

* RedHat Enterprise Linux 5, 6, 7
* Debian 6, 7, 8
* CentOS 5, 6, 7
* Ubuntu 10.04, 12.04, 14.04, 16.04
* Scientific Linux 5, 6
* SLES 11

Testing on other platforms has been minimal and cannot be guaranteed.

**Note:** The mysqlbackup.sh does not work and is not supported on MySQL 5.7 and greater.

Debian 9 compatibility has not been fully verified.

## Development

Puppet 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.

Check out our the complete [module contribution guide](https://docs.puppetlabs.com/forge/contributing.html).

### Authors

This module is based on work by David Schmitt. The following contributors have contributed to this module (beyond Puppet Labs):

* Larry Ludwig
* Christian G. Warden
* Daniel Black
* Justin Ellison
* Lowe Schmidt
* Matthias Pigulla
* William Van Hevelingen
* Michael Arnold
* Chris Weyl
* Daniël van Eeden
* Jan-Otto Kröpke
* Timothy Sven Nelson