Skip to content

Commit 825f020

Browse files
committed
fixup! fix(db): use caching_sha2_password for MySQL
1 parent 8db2ae8 commit 825f020

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

lib/private/Setup/MySQL.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,29 @@ private function createDatabase($connection): void {
9393
* @throws \OC\DatabaseSetupException
9494
*/
9595
private function createDBUser($connection): void {
96+
$name = $this->dbUser;
97+
$password = $this->dbPassword;
98+
9699
try {
97-
$name = $this->dbUser;
98-
$password = $this->dbPassword;
99100
// we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one,
100101
// the anonymous user would take precedence when there is one.
101102

102103
if ($connection->getDatabasePlatform() instanceof MySQL84Platform) {
103104
$query = "CREATE USER ?@'localhost' IDENTIFIED WITH caching_sha2_password BY ?";
104-
$connection->executeUpdate($query, [$name,$password]);
105+
$connection->executeStatement($query, [$name,$password]);
105106
$query = "CREATE USER ?@'%' IDENTIFIED WITH caching_sha2_password BY ?";
106-
$connection->executeUpdate($query, [$name,$password]);
107+
$connection->executeStatement($query, [$name,$password]);
107108
} elseif ($connection->getDatabasePlatform() instanceof Mysql80Platform) {
108-
// TODO: Remove this elseif section as soon as MySQL 8.0 is out-of-support (probably Nextcloud 33)
109+
// TODO: Remove this elseif section as soon as MySQL 8.0 is out-of-support (after April 2026)
109110
$query = "CREATE USER ?@'localhost' IDENTIFIED WITH mysql_native_password BY ?";
110-
$connection->executeUpdate($query, [$name,$password]);
111+
$connection->executeStatement($query, [$name,$password]);
111112
$query = "CREATE USER ?@'%' IDENTIFIED WITH mysql_native_password BY ?";
112-
$connection->executeUpdate($query, [$name,$password]);
113+
$connection->executeStatement($query, [$name,$password]);
113114
} else {
114115
$query = "CREATE USER ?@'localhost' IDENTIFIED BY ?";
115-
$connection->executeUpdate($query, [$name,$password]);
116+
$connection->executeStatement($query, [$name,$password]);
116117
$query = "CREATE USER ?@'%' IDENTIFIED BY ?";
117-
$connection->executeUpdate($query, [$name,$password]);
118+
$connection->executeStatement($query, [$name,$password]);
118119
}
119120
} catch (\Exception $ex) {
120121
$this->logger->error('Database user creation failed.', [
@@ -165,6 +166,11 @@ private function createSpecificUser($username, $connection): void {
165166
//use the admin login data for the new database user
166167
$this->dbUser = $adminUser;
167168
$this->createDBUser($connection);
169+
// if sharding is used we need to manually call this for every shard as those also need the user setup!
170+
/** @var ConnectionAdapter $connection */
171+
foreach ($connection->getInner()->getShardConnections() as $shard) {
172+
$this->createDBUser($shard);
173+
}
168174

169175
break;
170176
} else {

0 commit comments

Comments
 (0)