diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-07-22 18:50:11 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-07-22 23:02:06 +0200 |
commit | 1c12c00d3ddb34deb77256ccd24dff787a8e52a4 (patch) | |
tree | 4c34ff830b2601751e0fc682d104dc00ac7bbf88 | |
parent | 8db2ae8f0d4f8a82a4b6ba7bf6a55889fbee8dba (diff) | |
download | nextcloud-server-fix/mysql-removed-auth.tar.gz nextcloud-server-fix/mysql-removed-auth.zip |
fixup! fix(db): use `caching_sha2_password` for MySQLfix/mysql-removed-auth
-rw-r--r-- | lib/private/Setup/MySQL.php | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index 8606b76c1d1..c4794a86743 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -93,28 +93,29 @@ class MySQL extends AbstractDatabase { * @throws \OC\DatabaseSetupException */ private function createDBUser($connection): void { + $name = $this->dbUser; + $password = $this->dbPassword; + try { - $name = $this->dbUser; - $password = $this->dbPassword; // we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one, // the anonymous user would take precedence when there is one. if ($connection->getDatabasePlatform() instanceof MySQL84Platform) { $query = "CREATE USER ?@'localhost' IDENTIFIED WITH caching_sha2_password BY ?"; - $connection->executeUpdate($query, [$name,$password]); + $connection->executeStatement($query, [$name,$password]); $query = "CREATE USER ?@'%' IDENTIFIED WITH caching_sha2_password BY ?"; - $connection->executeUpdate($query, [$name,$password]); + $connection->executeStatement($query, [$name,$password]); } elseif ($connection->getDatabasePlatform() instanceof Mysql80Platform) { - // TODO: Remove this elseif section as soon as MySQL 8.0 is out-of-support (probably Nextcloud 33) + // TODO: Remove this elseif section as soon as MySQL 8.0 is out-of-support (after April 2026) $query = "CREATE USER ?@'localhost' IDENTIFIED WITH mysql_native_password BY ?"; - $connection->executeUpdate($query, [$name,$password]); + $connection->executeStatement($query, [$name,$password]); $query = "CREATE USER ?@'%' IDENTIFIED WITH mysql_native_password BY ?"; - $connection->executeUpdate($query, [$name,$password]); + $connection->executeStatement($query, [$name,$password]); } else { $query = "CREATE USER ?@'localhost' IDENTIFIED BY ?"; - $connection->executeUpdate($query, [$name,$password]); + $connection->executeStatement($query, [$name,$password]); $query = "CREATE USER ?@'%' IDENTIFIED BY ?"; - $connection->executeUpdate($query, [$name,$password]); + $connection->executeStatement($query, [$name,$password]); } } catch (\Exception $ex) { $this->logger->error('Database user creation failed.', [ @@ -165,6 +166,11 @@ class MySQL extends AbstractDatabase { //use the admin login data for the new database user $this->dbUser = $adminUser; $this->createDBUser($connection); + // if sharding is used we need to manually call this for every shard as those also need the user setup! + /** @var ConnectionAdapter $connection */ + foreach ($connection->getInner()->getShardConnections() as $shard) { + $this->createDBUser($shard); + } break; } else { |