From 0aa216fc483cb86eadd0f1e759406e4d679c949c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 5 Feb 2020 10:05:11 +0100 Subject: [PATCH 1/4] Only provide the auth method for MySQL 8.0+ to not break MariaDB Provide the auth method for MySQL 8.0+ Signed-off-by: Joas Schilling --- lib/private/Setup/MySQL.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index 3f4dd616a2..1ee650fecc 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -34,6 +34,7 @@ namespace OC\Setup; use OC\DB\MySqlTools; use OCP\IDBConnection; use OCP\ILogger; +use Doctrine\DBAL\Platforms\MySQL80Platform; class MySQL extends AbstractDatabase { public $dbprettyname = 'MySQL/MariaDB'; @@ -102,10 +103,18 @@ class MySQL extends AbstractDatabase { $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. - $query = "CREATE USER '$name'@'localhost' IDENTIFIED WITH mysql_native_password BY '$password'"; - $connection->executeUpdate($query); - $query = "CREATE USER '$name'@'%' IDENTIFIED WITH mysql_native_password BY '$password'"; - $connection->executeUpdate($query); + + if ($connection->getDatabasePlatform() instanceof Mysql80Platform) { + $query = "CREATE USER '$name'@'localhost' IDENTIFIED WITH mysql_native_password BY '$password'"; + $connection->executeUpdate($query); + $query = "CREATE USER '$name'@'%' IDENTIFIED WITH mysql_native_password BY '$password'"; + $connection->executeUpdate($query); + } else { + $query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'"; + $connection->executeUpdate($query); + $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'"; + $connection->executeUpdate($query); + } } catch (\Exception $ex){ $this->logger->logException($ex, [ From ac89b6abe71b7cea07413aa796f468c4df7eb16c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 5 Feb 2020 11:08:18 +0100 Subject: [PATCH 2/4] Check the new connection on setup like with PostgreSQL and Oracle Signed-off-by: Joas Schilling --- lib/private/Setup/MySQL.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index 1ee650fecc..7371c7aeab 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -58,6 +58,16 @@ class MySQL extends AbstractDatabase { //fill the database if needed $query='select count(*) from information_schema.tables where table_schema=? AND table_name = ?'; $connection->executeQuery($query, [$this->dbName, $this->tablePrefix.'users']); + + $connection->close(); + $connection = $this->connect(); + try { + $connection->connect(); + } catch (\Exception $e) { + $this->logger->logException($e); + throw new \OC\DatabaseSetupException($this->trans->t('MySQL username and/or password not valid'), + $this->trans->t('You need to enter details of an existing account.')); + } } /** From fca8f061abeaca295c76440c99b363f15c265d5b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 5 Feb 2020 11:00:37 +0100 Subject: [PATCH 3/4] Split the exception handling so install errors don't log as setup errors More gebuging Signed-off-by: Joas Schilling --- lib/private/Setup.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/private/Setup.php b/lib/private/Setup.php index a44b0fd488..acd75b88fb 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -353,11 +353,9 @@ class Setup { $this->config->setValues($newConfigValues); + $dbSetup->initialize($options); try { - $dbSetup->initialize($options); $dbSetup->setupDatabase($username); - // apply necessary migrations - $dbSetup->runMigrations(); } catch (\OC\DatabaseSetupException $e) { $error[] = [ 'error' => $e->getMessage(), @@ -371,6 +369,16 @@ class Setup { ]; return $error; } + try { + // apply necessary migrations + $dbSetup->runMigrations(); + } catch (Exception $e) { + $error[] = [ + 'error' => 'Error while trying to initialise the database: ' . $e->getMessage(), + 'hint' => '', + ]; + return $error; + } //create the user and group $user = null; From 0317c5b5c81d9df54c9b8c8c09c94cfdc60832e7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 5 Feb 2020 12:47:08 +0100 Subject: [PATCH 4/4] Correctly append the port to the host so it's written to the config correctly Signed-off-by: Joas Schilling --- core/Command/Maintenance/Install.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/Command/Maintenance/Install.php b/core/Command/Maintenance/Install.php index f92d86d024..fa18ef721b 100644 --- a/core/Command/Maintenance/Install.php +++ b/core/Command/Maintenance/Install.php @@ -134,6 +134,10 @@ class Install extends Command { } else { $dbHost = $input->getOption('database-host'); } + if ($dbPort) { + // Append the port to the host so it is the same as in the config (there is no dbport config) + $dbHost .= ':' . $dbPort; + } $dbTablePrefix = 'oc_'; if ($input->hasParameterOption('--database-table-prefix')) { $dbTablePrefix = (string) $input->getOption('database-table-prefix'); @@ -183,7 +187,6 @@ class Install extends Command { 'dbpass' => $dbPass, 'dbname' => $dbName, 'dbhost' => $dbHost, - 'dbport' => $dbPort, 'dbtableprefix' => $dbTablePrefix, 'adminlogin' => $adminLogin, 'adminpass' => $adminPassword,