Unable to share files on Nextcloud 13 instance with mysql db using utf8mb4 encoding

Nextcloud version (eg, 12.0.2): 13.0.4
Operating system and version (eg, Ubuntu 17.04): Ubuntu 18.04
Apache or nginx version (eg, Apache 2.4.25): nginx 1.14.0-0ubuntu1
PHP version (eg, 7.1): 7.2 (fpm)

The issue you are facing:

Attempting to share a file (with a user on the same instance) results in a crash.

Is this the first time you’ve seen this error? Yes

Steps to replicate it:

  1. Create Nextcloud MariaDB database with the following command (taken from documentation):
    CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
  2. Install Nextcloud 13/nginx/php as per the manual
  3. Add a user to the instance
  4. Attempt to share a file with that user

The output of your Nextcloud log in Admin > Logging:

Doctrine\DBAL\Exception\DriverException: An exception occurred while executing 'SELECT `c`.`carddata`, `c`.`uri` FROM `oc_cards` `c` WHERE `c`.`id` IN (SELECT DISTINCT `cp`.`cardid` FROM `oc_cards_properties` `cp` WHERE (`cp`.`addressbookid` = ?) AND ((`cp`.`name` = ?) OR (`cp`.`name` = ?)) AND (`cp`.`value` COLLATE utf8mb4_general_ci LIKE ?))' with params ["1", "CLOUD", "FN", "%park%"]: SQLSTATE[42000]: Syntax error or access violation: 1253 COLLATION 'utf8mb4_general_ci' is not valid for CHARACTER SET 'utf8'

    /var/www/cloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php - line 128: Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\PDOException))
    /var/www/cloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php - line 855: Doctrine\DBAL\DBALException driverExceptionDuringQuery(Object(Doctrine\DBAL\Driver\PDOMySql\Driver), Object(Doctrine\DBAL\Driver\PDOException), 'SELECT `c`.`car...', Array)
    /var/www/cloud/lib/private/DB/Connection.php - line 195: Doctrine\DBAL\Connection->executeQuery('SELECT `c`.`car...', Array, Array, NULL)
    /var/www/cloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php - line 206: OC\DB\Connection->executeQuery('SELECT `c`.`car...', Array, Array)
    /var/www/cloud/lib/private/DB/QueryBuilder/QueryBuilder.php - line 214: Doctrine\DBAL\Query\QueryBuilder->execute()
    /var/www/cloud/apps/dav/lib/CardDAV/CardDavBackend.php - line 910: OC\DB\QueryBuilder\QueryBuilder->execute()
    /var/www/cloud/apps/dav/lib/CardDAV/AddressBookImpl.php - line 96: OCA\DAV\CardDAV\CardDavBackend->search('1', 'park', Array)
    /var/www/cloud/lib/private/ContactsManager.php - line 45: OCA\DAV\CardDAV\AddressBookImpl->search('park', Array, Array)
    /var/www/cloud/lib/private/Collaboration/Collaborators/RemotePlugin.php - line 59: OC\ContactsManager->search('park', Array)
    /var/www/cloud/lib/private/Collaboration/Collaborators/Search.php - line 65: OC\Collaboration\Collaborators\RemotePlugin->search('park', 200, 0, Object(OC\Collaboration\Collaborators\SearchResult))
    /var/www/cloud/apps/files_sharing/lib/Controller/ShareesAPIController.php - line 181: OC\Collaboration\Collaborators\Search->search('park', Array, true, 200, 0)
    [internal function] OCA\Files_Sharing\Controller\ShareesAPIController->search('park', 'folder', 1, 200, NULL, true)
    /var/www/cloud/lib/private/AppFramework/Http/Dispatcher.php - line 161: call_user_func_array(Array, Array)
    /var/www/cloud/lib/private/AppFramework/Http/Dispatcher.php - line 91: OC\AppFramework\Http\Dispatcher->executeController(Object(OCA\Files_Sharing\Controller\ShareesAPIController), 'search')
    /var/www/cloud/lib/private/AppFramework/App.php - line 115: OC\AppFramework\Http\Dispatcher->dispatch(Object(OCA\Files_Sharing\Controller\ShareesAPIController), 'search')
    /var/www/cloud/lib/private/AppFramework/Routing/RouteActionHandler.php - line 47: OC\AppFramework\App main('OCA\\Files_Shari...', 'search', Object(OC\AppFramework\DependencyInjection\DIContainer), Array)
    [internal function] OC\AppFramework\Routing\RouteActionHandler->__invoke(Array)
    /var/www/cloud/lib/private/Route/Router.php - line 297: call_user_func(Object(OC\AppFramework\Routing\RouteActionHandler), Array)
    /var/www/cloud/ocs/v1.php - line 78: OC\Route\Router->match('/ocsapp/apps/fi...')
    {main}

The output of your config.php file in /var/www/cloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => 'instanceidunique',
  'passwordsalt' => 'randomsalt',
  'secret' => 'randomsecret',
  'trusted_domains' => 
  array (
    0 => 'cloud.nextcloud.com',
  ),
  'datadirectory' => '/var/www/cloud/data',
  'overwrite.cli.url' => 'https://cloud.nextcloud.com',
  'dbtype' => 'mysql',
  'version' => '13.0.4.0',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nextcloud',
  'dbpassword' => 'databasepassword',
  'installed' => true,
  'mysql.utf8mb4' => true,
  'memcache.local' => '\OC\Memcache\APCu',
);

The output of your Apache/nginx/system log in /var/log/____:
no errors

I was able to resolve my problem by changing my database back to utf8. I would still like a solution that wokrs with utf8mb4

Hello,
I have the same difficulty as you, even in version 14. I am required to have a utf8mb4 database to use the News application and, this configuration is not compatible with file sharing features. Does anyone know what we can do?
Thank you.
Have a nice day :grinning: