Merge pull request #4514 from nextcloud/automatic-mysql-4byte-detection
Automatic mysql 4byte detection
This commit is contained in:
commit
4d101ca2be
|
@ -1235,16 +1235,23 @@ $CONFIG = array(
|
||||||
'sqlite.journal_mode' => 'DELETE',
|
'sqlite.journal_mode' => 'DELETE',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this setting is set to true MySQL can handle 4 byte characters instead of
|
* During setup, if requirements are met (see below), this setting is set to true
|
||||||
* 3 byte characters
|
* and MySQL can handle 4 byte characters instead of 3 byte characters.
|
||||||
*
|
*
|
||||||
|
* If you want to convert an existing 3-byte setup into a 4-byte setup please
|
||||||
|
* set the parameters in MySQL as mentioned below and run the migration command:
|
||||||
|
* ./occ db:convert-mysql-charset
|
||||||
|
* The config setting will be set automatically after a successful run.
|
||||||
|
*
|
||||||
|
* Consult the documentation for more details.
|
||||||
|
*
|
||||||
* MySQL requires a special setup for longer indexes (> 767 bytes) which are
|
* MySQL requires a special setup for longer indexes (> 767 bytes) which are
|
||||||
* needed:
|
* needed:
|
||||||
*
|
*
|
||||||
* [mysqld]
|
* [mysqld]
|
||||||
* innodb_large_prefix=true
|
* innodb_large_prefix=ON
|
||||||
* innodb_file_format=barracuda
|
* innodb_file_format=Barracuda
|
||||||
* innodb_file_per_table=true
|
* innodb_file_per_table=ON
|
||||||
*
|
*
|
||||||
* Tables will be created with
|
* Tables will be created with
|
||||||
* * character set: utf8mb4
|
* * character set: utf8mb4
|
||||||
|
@ -1257,8 +1264,6 @@ $CONFIG = array(
|
||||||
* https://mariadb.com/kb/en/mariadb/xtradbinnodb-server-system-variables/#innodb_large_prefix
|
* https://mariadb.com/kb/en/mariadb/xtradbinnodb-server-system-variables/#innodb_large_prefix
|
||||||
* http://www.tocker.ca/2013/10/31/benchmarking-innodb-page-compression-performance.html
|
* http://www.tocker.ca/2013/10/31/benchmarking-innodb-page-compression-performance.html
|
||||||
* http://mechanics.flite.com/blog/2014/07/29/using-innodb-large-prefix-to-avoid-error-1071/
|
* http://mechanics.flite.com/blog/2014/07/29/using-innodb-large-prefix-to-avoid-error-1071/
|
||||||
*
|
|
||||||
* WARNING: EXPERIMENTAL
|
|
||||||
*/
|
*/
|
||||||
'mysql.utf8mb4' => false,
|
'mysql.utf8mb4' => false,
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
namespace OC\Core\Command\Db;
|
namespace OC\Core\Command\Db;
|
||||||
|
|
||||||
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||||
|
use OC\DB\MySqlTools;
|
||||||
use OC\Migration\ConsoleOutput;
|
use OC\Migration\ConsoleOutput;
|
||||||
use OC\Repair\Collation;
|
use OC\Repair\Collation;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
@ -71,18 +72,17 @@ class ConvertMysqlToMB4 extends Command {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$oldValue = $this->config->getSystemValue('mysql.utf8mb4', false);
|
$tools = new MySqlTools();
|
||||||
// enable charset
|
if (!$tools->supports4ByteCharset($this->connection)) {
|
||||||
$this->config->setSystemValue('mysql.utf8mb4', true);
|
|
||||||
|
|
||||||
if (!$this->connection->supports4ByteText()) {
|
|
||||||
$url = $this->urlGenerator->linkToDocs('admin-mysql-utf8mb4');
|
$url = $this->urlGenerator->linkToDocs('admin-mysql-utf8mb4');
|
||||||
$output->writeln("The database is not properly setup to use the charset utf8mb4.");
|
$output->writeln("The database is not properly setup to use the charset utf8mb4.");
|
||||||
$output->writeln("For more information please read the documentation at $url");
|
$output->writeln("For more information please read the documentation at $url");
|
||||||
$this->config->setSystemValue('mysql.utf8mb4', $oldValue);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// enable charset
|
||||||
|
$this->config->setSystemValue('mysql.utf8mb4', true);
|
||||||
|
|
||||||
// run conversion
|
// run conversion
|
||||||
$coll = new Collation($this->config, $this->logger, $this->connection, false);
|
$coll = new Collation($this->config, $this->logger, $this->connection, false);
|
||||||
$coll->run(new ConsoleOutput($output));
|
$coll->run(new ConsoleOutput($output));
|
||||||
|
|
|
@ -488,6 +488,7 @@ return array(
|
||||||
'OC\\DB\\MigrationException' => $baseDir . '/lib/private/DB/MigrationException.php',
|
'OC\\DB\\MigrationException' => $baseDir . '/lib/private/DB/MigrationException.php',
|
||||||
'OC\\DB\\Migrator' => $baseDir . '/lib/private/DB/Migrator.php',
|
'OC\\DB\\Migrator' => $baseDir . '/lib/private/DB/Migrator.php',
|
||||||
'OC\\DB\\MySQLMigrator' => $baseDir . '/lib/private/DB/MySQLMigrator.php',
|
'OC\\DB\\MySQLMigrator' => $baseDir . '/lib/private/DB/MySQLMigrator.php',
|
||||||
|
'OC\\DB\\MySqlTools' => $baseDir . '/lib/private/DB/MySqlTools.php',
|
||||||
'OC\\DB\\NoCheckMigrator' => $baseDir . '/lib/private/DB/NoCheckMigrator.php',
|
'OC\\DB\\NoCheckMigrator' => $baseDir . '/lib/private/DB/NoCheckMigrator.php',
|
||||||
'OC\\DB\\OCSqlitePlatform' => $baseDir . '/lib/private/DB/OCSqlitePlatform.php',
|
'OC\\DB\\OCSqlitePlatform' => $baseDir . '/lib/private/DB/OCSqlitePlatform.php',
|
||||||
'OC\\DB\\OracleConnection' => $baseDir . '/lib/private/DB/OracleConnection.php',
|
'OC\\DB\\OracleConnection' => $baseDir . '/lib/private/DB/OracleConnection.php',
|
||||||
|
|
|
@ -518,6 +518,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
|
||||||
'OC\\DB\\MigrationException' => __DIR__ . '/../../..' . '/lib/private/DB/MigrationException.php',
|
'OC\\DB\\MigrationException' => __DIR__ . '/../../..' . '/lib/private/DB/MigrationException.php',
|
||||||
'OC\\DB\\Migrator' => __DIR__ . '/../../..' . '/lib/private/DB/Migrator.php',
|
'OC\\DB\\Migrator' => __DIR__ . '/../../..' . '/lib/private/DB/Migrator.php',
|
||||||
'OC\\DB\\MySQLMigrator' => __DIR__ . '/../../..' . '/lib/private/DB/MySQLMigrator.php',
|
'OC\\DB\\MySQLMigrator' => __DIR__ . '/../../..' . '/lib/private/DB/MySQLMigrator.php',
|
||||||
|
'OC\\DB\\MySqlTools' => __DIR__ . '/../../..' . '/lib/private/DB/MySqlTools.php',
|
||||||
'OC\\DB\\NoCheckMigrator' => __DIR__ . '/../../..' . '/lib/private/DB/NoCheckMigrator.php',
|
'OC\\DB\\NoCheckMigrator' => __DIR__ . '/../../..' . '/lib/private/DB/NoCheckMigrator.php',
|
||||||
'OC\\DB\\OCSqlitePlatform' => __DIR__ . '/../../..' . '/lib/private/DB/OCSqlitePlatform.php',
|
'OC\\DB\\OCSqlitePlatform' => __DIR__ . '/../../..' . '/lib/private/DB/OCSqlitePlatform.php',
|
||||||
'OC\\DB\\OracleConnection' => __DIR__ . '/../../..' . '/lib/private/DB/OracleConnection.php',
|
'OC\\DB\\OracleConnection' => __DIR__ . '/../../..' . '/lib/private/DB/OracleConnection.php',
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2017, ownCloud GmbH
|
||||||
|
* @license AGPL-3.0
|
||||||
|
*
|
||||||
|
* This code is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3,
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OC\DB;
|
||||||
|
|
||||||
|
use OCP\IDBConnection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Various MySQL specific helper functions.
|
||||||
|
*/
|
||||||
|
class MySqlTools {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Connection $connection
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function supports4ByteCharset(IDBConnection $connection) {
|
||||||
|
foreach (['innodb_file_format' => 'Barracuda', 'innodb_large_prefix' => 'ON', 'innodb_file_per_table' => 'ON'] as $var => $val) {
|
||||||
|
$result = $connection->executeQuery("SHOW VARIABLES LIKE '$var'");
|
||||||
|
$rows = $result->fetch();
|
||||||
|
$result->closeCursor();
|
||||||
|
if ($rows === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (strcasecmp($rows['Value'], $val) !== 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,7 @@
|
||||||
*/
|
*/
|
||||||
namespace OC\Setup;
|
namespace OC\Setup;
|
||||||
|
|
||||||
|
use OC\DB\MySqlTools;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
|
|
||||||
class MySQL extends AbstractDatabase {
|
class MySQL extends AbstractDatabase {
|
||||||
|
@ -36,6 +37,13 @@ class MySQL extends AbstractDatabase {
|
||||||
//check if the database user has admin right
|
//check if the database user has admin right
|
||||||
$connection = $this->connect(['dbname' => null]);
|
$connection = $this->connect(['dbname' => null]);
|
||||||
|
|
||||||
|
// detect mb4
|
||||||
|
$tools = new MySqlTools();
|
||||||
|
if ($tools->supports4ByteCharset($connection)) {
|
||||||
|
$this->config->setValue('mysql.utf8mb4', true);
|
||||||
|
$connection = $this->connect();
|
||||||
|
}
|
||||||
|
|
||||||
$this->createSpecificUser($username, $connection);
|
$this->createSpecificUser($username, $connection);
|
||||||
|
|
||||||
//create the database
|
//create the database
|
||||||
|
|
Loading…
Reference in New Issue