Skip to content

Commit e289392

Browse files
authored
Merge pull request #1092 from zpetr/master
MySQL 8 compatibility in user management
2 parents 1766b85 + 8cb6587 commit e289392

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/puppet/provider/mysql_user/mysql.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,28 @@ def create
6262
# Use CREATE USER to be compatible with NO_AUTO_CREATE_USER sql_mode
6363
# This is also required if you want to specify a authentication plugin
6464
if !plugin.nil?
65-
if plugin == 'sha256_password' && !password_hash.nil?
65+
if !password_hash.nil?
6666
self.class.mysql_caller("CREATE USER '#{merged_name}' IDENTIFIED WITH '#{plugin}' AS '#{password_hash}'", 'system')
6767
else
6868
self.class.mysql_caller("CREATE USER '#{merged_name}' IDENTIFIED WITH '#{plugin}'", 'system')
6969
end
7070
@property_hash[:ensure] = :present
7171
@property_hash[:plugin] = plugin
72+
elsif newer_than('mysql' => '5.7.6', 'percona' => '5.7.6')
73+
self.class.mysql_caller("CREATE USER '#{merged_name}' IDENTIFIED WITH 'mysql_native_password' AS '#{password_hash}'", 'system')
74+
@property_hash[:ensure] = :present
75+
@property_hash[:password_hash] = password_hash
7276
else
7377
self.class.mysql_caller("CREATE USER '#{merged_name}' IDENTIFIED BY PASSWORD '#{password_hash}'", 'system')
7478
@property_hash[:ensure] = :present
7579
@property_hash[:password_hash] = password_hash
7680
end
7781
# rubocop:disable Metrics/LineLength
78-
self.class.mysql_caller("GRANT USAGE ON *.* TO '#{merged_name}' WITH MAX_USER_CONNECTIONS #{max_user_connections} MAX_CONNECTIONS_PER_HOUR #{max_connections_per_hour} MAX_QUERIES_PER_HOUR #{max_queries_per_hour} MAX_UPDATES_PER_HOUR #{max_updates_per_hour}", 'system')
82+
if newer_than('mysql' => '5.7.6', 'percona' => '5.7.6')
83+
self.class.mysql_caller("ALTER USER IF EXISTS '#{merged_name}' WITH MAX_USER_CONNECTIONS #{max_user_connections} MAX_CONNECTIONS_PER_HOUR #{max_connections_per_hour} MAX_QUERIES_PER_HOUR #{max_queries_per_hour} MAX_UPDATES_PER_HOUR #{max_updates_per_hour}", 'system')
84+
else
85+
self.class.mysql_caller("GRANT USAGE ON *.* TO '#{merged_name}' WITH MAX_USER_CONNECTIONS #{max_user_connections} MAX_CONNECTIONS_PER_HOUR #{max_connections_per_hour} MAX_QUERIES_PER_HOUR #{max_queries_per_hour} MAX_UPDATES_PER_HOUR #{max_updates_per_hour}", 'system')
86+
end
7987
# rubocop:enable Metrics/LineLength
8088
@property_hash[:max_user_connections] = max_user_connections
8189
@property_hash[:max_connections_per_hour] = max_connections_per_hour

manifests/params.pp

-2
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,6 @@
474474
'max_connections' => '151',
475475
'pid-file' => $mysql::params::pidfile,
476476
'port' => '3306',
477-
'query_cache_limit' => '1M',
478-
'query_cache_size' => '16M',
479477
'skip-external-locking' => true,
480478
'socket' => $mysql::params::socket,
481479
'ssl' => false,

0 commit comments

Comments
 (0)