diff -u b/core/lib/Drupal/Core/Database/Connection.php b/core/lib/Drupal/Core/Database/Connection.php --- b/core/lib/Drupal/Core/Database/Connection.php +++ b/core/lib/Drupal/Core/Database/Connection.php @@ -1153,13 +1153,6 @@ } /** - * Returns the version of the database client. - */ - public function clientVersion() { - return $this->connection->getAttribute(\PDO::ATTR_CLIENT_VERSION); - } - - /** * Determines if this driver supports transactions. * * @return @@ -1224,6 +1217,13 @@ } /** + * Returns the version of the database client. + */ + public function clientVersion() { + return $this->connection->getAttribute(\PDO::ATTR_CLIENT_VERSION); + } + + /** * Determines if this driver supports transactions. * * @return bool reverted: --- b/core/lib/Drupal/Core/Database/Database.php +++ a/core/lib/Drupal/Core/Database/Database.php @@ -40,15 +40,6 @@ const RETURN_INSERT_ID = 3; /** - * Flag to indicate whether the MySQL DSN charset should fall back to utf8. - * - * Used in installer version checks. - * - * @var boolean - */ - static protected $mysql_dsn_utf8_fallback = FALSE; - - /** * An nested array of all active connections. It is keyed by database name * and target. * @@ -150,12 +141,6 @@ return $queries; } - final public static getConnectionWithUtf8Dsn($target = 'default', $key = NULL) { - self::$mysql_dsn_utf8_fallback = TRUE; - self::getConnection($target, $key); - self::$mysql_dsn_utf8_fallback = FALSE; - } - /** * Gets the connection object for the specified database key and target. * @@ -393,11 +378,7 @@ $driver_class = "Drupal\\Core\\Database\\Driver\\{$driver}\\Connection"; } + $pdo_connection = $driver_class::open(self::$databaseInfo[$key][$target]); - $connection_options = self::$databaseInfo[$key][$target]; - if ($driver == 'mysql' && self::$mysql_dsn_utf8_fallback === TRUE) { - $connection_options += array('mysql_dsn_utf8_fallback' => TRUE); - } - $pdo_connection = $driver_class::open($connection_options); $new_connection = new $driver_class($pdo_connection, self::$databaseInfo[$key][$target]); $new_connection->setTarget($target); $new_connection->setKey($key); diff -u b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php --- b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php @@ -41,6 +41,15 @@ protected $needsCleanup = FALSE; /** + * Flag to indicate whether the MySQL DSN charset should fall back to utf8. + * + * Should be used in installer version checks only. + * + * @var boolean + */ + static public $dsnUtf8Fallback = FALSE; + + /** * The minimal possible value for the max_allowed_packet setting of MySQL. * * @link https://mariadb.com/kb/en/mariadb/server-system-variables/#max_allowed_packet @@ -69,12 +78,7 @@ // Character set is added to dsn to ensure PDO uses the proper character // set when escaping. This has security implications. See // https://www.drupal.org/node/1201452 for further discussion. - if (empty($connection_options['mysql_dsn_utf8_fallback'])) { - $dsn .= ';charset=utf8mb4'; - } - else { - $dsn .= ';charset=utf8'; - } + $dsn .= ';charset=utf8mb4'; if (!empty($connection_options['database'])) { $dsn .= ';dbname=' . $connection_options['database']; } @@ -92,6 +96,13 @@ * {@inheritdoc} */ public static function open(array &$connection_options = array()) { + if (static::$dsnUtf8Fallback === TRUE) { + // Only used during the installer version check, as a fallback from utf8mb4. + $charset = 'utf8'; + } + else { + $charset = 'utf8mb4'; + } // The DSN should use either a socket or a host/port. if (isset($connection_options['unix_socket'])) { $dsn = 'mysql:unix_socket=' . $connection_options['unix_socket']; @@ -103,7 +114,13 @@ // Character set is added to dsn to ensure PDO uses the proper character // set when escaping. This has security implications. See // https://www.drupal.org/node/1201452 for further discussion. - $dsn .= ';charset=utf8mb4'; + if (static::$dsnUtf8Fallback === TRUE) { + // Only used during the installer version check, as a fallback from utf8mb4. + $dsn .= ';charset=' . $charset; + } + else { + $dsn .= ';charset=' . $charset; + } if (!empty($connection_options['database'])) { $dsn .= ';dbname=' . $connection_options['database']; } @@ -134,10 +151,10 @@ // certain one has been set; otherwise, MySQL defaults to // 'utf8mb4_general_ci' for utf8mb4. if (!empty($connection_options['collation'])) { - $pdo->exec('SET NAMES utf8mb4 COLLATE ' . $connection_options['collation']); + $pdo->exec('SET NAMES ' . $charset . ' COLLATE ' . $connection_options['collation']); } else { - $pdo->exec('SET NAMES utf8mb4'); + $pdo->exec('SET NAMES ' . $charset); } // Set MySQL init_commands if not already defined. Default Drupal's MySQL diff -u b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php --- b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php @@ -16,6 +16,17 @@ * Specifies installation tasks for MySQL and equivalent databases. */ class Tasks extends InstallTasks { + + /** + * Minimum required MySQLnd version. + */ + const MYSQLND_MINIMUM_VERSION = '5.0.9'; + + /** + * Minimum required libmysqlclient version. + */ + const LIBMYSQLCLIENT_MINIMUM_VERSION = '5.5.3'; + /** * The PDO driver name for MySQL and equivalent databases. * @@ -62,7 +73,9 @@ // Detect utf8mb4 incompability. if ($e->getCode() == Connection::UNSUPPORTED_CHARSET) { $this->fail(t('Your mysql server and PHP mysql driver must support utf8mb4 character encoding to work with Drupal. Make sure to use a database system that supports utf8mb4 character encoding, such as MySQL/MariaDB/Percona versions 5.5.3 and up, and that the utf8mb4 character set is compiled in. See the MySQL documentation for more information.', array('@documentation' => 'https://dev.mysql.com/doc/refman/5.0/en/cannot-initialize-character-set.html'))); - Database::getConnectionWithUtf8Dsn(); + Connection::$dsnUtf8Fallback = TRUE; + Database::getConnection(); + Connection::$dsnUtf8Fallback = FALSE; } else { // Rethrow the exception. @@ -129,2 +142,25 @@ + /** + * {@inheritdoc} + */ + protected function checkEngineVersion() { + parent::checkEngineVersion(); + + // Ensure that the MySQL driver supports utf8mb4 encoding. + $version = Database::getConnection()->clientVersion(); + if (FALSE !== strpos($version, 'mysqlnd')) { + // The mysqlnd driver supports utf8mb4 starting at version 5.0.9. + $version = preg_replace('/^\D+([\d.]+).*/', '$1', $version); + if (version_compare($version, self::MYSQLND_MINIMUM_VERSION, '<')) { + $this->fail(t("The MySQLnd driver version %version is less than the minimum required version %minimum_version.", array('%version' => Database::getConnection()->version(), '%minimum_version' => self::MYSQLND_MINIMUM_VERSION))); + } + } + else { + // The libmysqlclient driver supports utf8mb4 starting at version 5.5.3. + if (version_compare($version, self::LIBMYSQLCLIENT_MINIMUM_VERSION, '<')) { + $this->fail(t("The libmysqlclient driver version %version is less than the minimum required version %minimum_version.", array('%version' => Database::getConnection()->version(), '%minimum_version' => self::LIBMYSQLCLIENT_MINIMUM_VERSION))); + } + } + } + } diff -u b/core/lib/Drupal/Core/Database/Install/Tasks.php b/core/lib/Drupal/Core/Database/Install/Tasks.php --- b/core/lib/Drupal/Core/Database/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Install/Tasks.php @@ -148,14 +148,14 @@ } } // Check for failed results and compile message - $message = ''; + $messages = array(); foreach ($this->results as $result => $success) { if (!$success) { - $message = SafeMarkup::isSafe($result) ? $result : SafeMarkup::checkPlain($result); + $messages[] = SafeMarkup::isSafe($result) ? $result : '