Skip to content

Commit 41dd8eb

Browse files
author
Marius Burkard
committed
- backported mysql password change fix from master
1 parent c03f4d6 commit 41dd8eb

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

server/plugins-available/mysql_clientdb_plugin.inc.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,26 @@ function db_user_update($event_name, $data) {
686686
}
687687

688688
if($data['new']['database_password'] != $data['old']['database_password'] && $data['new']['database_password'] != '') {
689-
$link->query("SET PASSWORD FOR '".$link->escape_string($data['new']['database_user'])."'@'$db_host' = '".$link->escape_string($data['new']['database_password'])."';");
690-
$app->log('Changing MySQL user password for: '.$data['new']['database_user'].'@'.$db_host, LOGLEVEL_DEBUG);
689+
$result = $app->db->queryOneRecord("SELECT VERSION() as version");
690+
$dbversion = $result['version'];
691+
692+
// mariadb or mysql < 5.7
693+
if(stripos($dbversion, 'mariadb') !== false || version_compare($dbversion, '5.7', '<')) {
694+
$query = sprintf("SET PASSWORD FOR '%s'@'%s' = '%s'",
695+
$link->escape_string($data['new']['database_user']),
696+
$db_host,
697+
$link->escape_string($data['new']['database_password']));
698+
$link->query($query);
699+
}
700+
// mysql >= 5.7
701+
else {
702+
$query = sprintf("ALTER USER IF EXISTS '%s'@'%s' IDENTIFIED WITH mysql_native_password AS '%s'",
703+
$link->escape_string($data['new']['database_user']),
704+
$db_host,
705+
$link->escape_string($data['new']['database_password']));
706+
$link->query($query);
707+
}
708+
$app->log('Changing MySQL user password for: ' . $data['new']['database_user'] . '@' . $db_host, LOGLEVEL_DEBUG);
691709
}
692710
}
693711

0 commit comments

Comments
 (0)