|
8 | 8 | namespace OC\Setup; |
9 | 9 |
|
10 | 10 | use Doctrine\DBAL\Platforms\MySQL80Platform; |
| 11 | +use Doctrine\DBAL\Platforms\MySQL84Platform; |
11 | 12 | use OC\DB\ConnectionAdapter; |
12 | 13 | use OC\DB\MySqlTools; |
13 | 14 | use OCP\IDBConnection; |
@@ -92,22 +93,29 @@ private function createDatabase($connection): void { |
92 | 93 | * @throws \OC\DatabaseSetupException |
93 | 94 | */ |
94 | 95 | private function createDBUser($connection): void { |
| 96 | + $name = $this->dbUser; |
| 97 | + $password = $this->dbPassword; |
| 98 | + |
95 | 99 | try { |
96 | | - $name = $this->dbUser; |
97 | | - $password = $this->dbPassword; |
98 | 100 | // we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one, |
99 | 101 | // the anonymous user would take precedence when there is one. |
100 | 102 |
|
101 | | - if ($connection->getDatabasePlatform() instanceof Mysql80Platform) { |
| 103 | + if ($connection->getDatabasePlatform() instanceof MySQL84Platform) { |
| 104 | + $query = "CREATE USER ?@'localhost' IDENTIFIED WITH caching_sha2_password BY ?"; |
| 105 | + $connection->executeStatement($query, [$name,$password]); |
| 106 | + $query = "CREATE USER ?@'%' IDENTIFIED WITH caching_sha2_password BY ?"; |
| 107 | + $connection->executeStatement($query, [$name,$password]); |
| 108 | + } elseif ($connection->getDatabasePlatform() instanceof Mysql80Platform) { |
| 109 | + // TODO: Remove this elseif section as soon as MySQL 8.0 is out-of-support (after April 2026) |
102 | 110 | $query = "CREATE USER ?@'localhost' IDENTIFIED WITH mysql_native_password BY ?"; |
103 | | - $connection->executeUpdate($query, [$name,$password]); |
| 111 | + $connection->executeStatement($query, [$name,$password]); |
104 | 112 | $query = "CREATE USER ?@'%' IDENTIFIED WITH mysql_native_password BY ?"; |
105 | | - $connection->executeUpdate($query, [$name,$password]); |
| 113 | + $connection->executeStatement($query, [$name,$password]); |
106 | 114 | } else { |
107 | 115 | $query = "CREATE USER ?@'localhost' IDENTIFIED BY ?"; |
108 | | - $connection->executeUpdate($query, [$name,$password]); |
| 116 | + $connection->executeStatement($query, [$name,$password]); |
109 | 117 | $query = "CREATE USER ?@'%' IDENTIFIED BY ?"; |
110 | | - $connection->executeUpdate($query, [$name,$password]); |
| 118 | + $connection->executeStatement($query, [$name,$password]); |
111 | 119 | } |
112 | 120 | } catch (\Exception $ex) { |
113 | 121 | $this->logger->error('Database user creation failed.', [ |
@@ -158,6 +166,11 @@ private function createSpecificUser($username, $connection): void { |
158 | 166 | //use the admin login data for the new database user |
159 | 167 | $this->dbUser = $adminUser; |
160 | 168 | $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 | + } |
161 | 174 |
|
162 | 175 | break; |
163 | 176 | } else { |
|
0 commit comments