view modules/website/manifests/mysql.pp @ 215:680a6eeaa0a6 puppet-3.6

Make database connections default to UTF-8 Prior to this, "…" was stored correctly but served as the Unicode replacement character � because the DB was UTF-8, the output was UTF-8 but the mysql connection was defaulting to latin1
author IBBoard <dev@ibboard.co.uk>
date Thu, 01 Aug 2019 20:26:58 +0100
parents b13e0de66b54
children 48b154d5ea53
line wrap: on
line source

class website::mysql (
  $mysqluser,
  $mysqlpassword,
  $mysqlsuffix    = '',
  $phpsuffix      = '',
  $phpmysqlsuffix = '',
  $mysqlprefix    = 'mysql')
  {
  class { 'mysql::client':
    package_name    => "${mysqlprefix}${mysqlsuffix}",
    bindings_enable => false, #Deal with bindings manually
  }
  class { 'mysql::bindings':
    php_enable       => true,
    php_package_name => "php${phpsuffix}-mysql${phpmysqlsuffix}",
  }
  class { 'mysql::server':
    package_name => "${mysqlprefix}${mysqlsuffix}-server",
    override_options => {
      'mysqld' => {
        'query_cache_size' => '64M',
        'join_buffer_size' => '524288', #512K
        'tmp_table_size'   => '64M',
        'max_heap_table_size' => '64M',
        'table_open_cache' => '64',
        'log-queries-not-using-indexes' => '1',
        # Set a sensible default character set
        'character-set-server' => 'utf8',
        'collation-server' => 'utf8_general_ci',
        # Settings for best MySQL 4-byte Unicode support
        'innodb_large_prefix' => 'true',
        'innodb_file_format' => 'barracuda',
        'innodb_file_per_table' => '1',
      }
    },
  }
  $username = strip($mysqluser)
  $password = strip($mysqlpassword)
  $configured_marker = "/etc/.${mysqlprefix}.is-configured"
  exec { 'Rename root MySQL user for security':
    command  => "mysql -uroot -e 'UPDATE mysql.user SET User = \"$username\", Password = PASSWORD(\"$password\") WHERE User = \"root\"; DELETE FROM mysql.user WHERE User = \"\"; FLUSH PRIVILEGES;' && touch $configured_marker",
    provider => shell,
    creates  => $configured_marker,
    require  => Class['mysql::server'],
  }
}