Skip to content

Commit 407bd7c

Browse files
author
Timo Boldt
committed
fixed mysql password update on mysql > 5.7
See issue #4321
1 parent e41378e commit 407bd7c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

server/plugins-available/mysql_clientdb_plugin.inc.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,19 @@ function db_user_update($event_name, $data) {
680680
}
681681

682682
if($data['new']['database_password'] != $data['old']['database_password'] && $data['new']['database_password'] != '') {
683-
$link->query("SET PASSWORD FOR '".$link->escape_string($data['new']['database_user'])."'@'$db_host' = '".$link->escape_string($data['new']['database_password'])."';");
683+
$result = $app->db->queryOneRecord("SELECT VERSION() as version");
684+
$dbversion = $result['version'];
685+
686+
if (version_compare($dbversion, '5.7') >= 0) {
687+
$query = sprintf("ALTER USER IF EXISTS '%s'@'%s' IDENTIFIED WITH mysql_native_password AS '%s';",
688+
$link->escape_string($data['new']['database_user']),
689+
$db_host,
690+
$link->escape_string($data['new']['database_password']));
691+
$link->query($query);
692+
}
693+
else {
694+
$link->query("SET PASSWORD FOR '".$link->escape_string($data['new']['database_user'])."'@'$db_host' = '".$link->escape_string($data['new']['database_password'])."';");
695+
}
684696
$app->log('Changing MySQL user password for: '.$data['new']['database_user'].'@'.$db_host, LOGLEVEL_DEBUG);
685697
}
686698
}

0 commit comments

Comments
 (0)