Nextcloud & MySQL

I have a fairly standard nextcloud setup with a fairly standard mysql setup:

services.mysql = {
  enable = true;
  package = pkgs.mariadb;
  ensureDatabases = [
    "nextcloud"
  ];
  ensureUsers = {
    name = "nextcloud";
    ensurePermissions = {
      "nextcloud.*" = "ALL PRIVILEGES";
    };
  };
};

services.nextcloud.config.dbtype = "mysql";

But I get: SQLSTATE[HY000] [1044] Access denied for user 'nextcloud'@'localhost' to database 'nextcloud' in the logs, and the nextcloud service doesn’t start up.

On the console I have:

# mysql -u nextcloud
ERROR 1698 (28000): Access denied for user 'nextcloud'@'localhost'

But:

mysql> SELECT User, Host, plugin FROM mysql.user;
+------------------+-----------+-----------------------+
| User             | Host      | plugin                |
+------------------+-----------+-----------------------+
| mysql            | localhost | auth_socket           |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
| mysqlbackup      | localhost | auth_socket           |
| nextcloud        | localhost | auth_socket           |
| root             | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
7 rows in set (0.00 sec)

Also, runuser -u nextcloud -- mysql succeeds.

So is the issue that nextcloud doesn’t try to access over auth_socket, but over password, and this fails?

Not really. After setting services.nextcloud.config.dbpass and doing this:

alter user nextcloud@localhost identified with caching_sha2_password by 'somepassword';

It still shows the same error.

I should add that I’m trying to migrate from SQLite.

Also trying to convert the database beforehand fails:

# nextcloud-occ db:convert-type mysql nextcloud localhost nextcloud
What is the database password?
Creating schema in new database

In Connection.php line 85:
                                                                                                                                                                         
  Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [1044] Access denied for user 'nextcloud'@'localhost' to database 'nextcloud'  
                                                                                                                                                                         

db:convert-type [--port PORT] [--password PASSWORD] [--clear-schema] [--all-apps] [--chunk-size CHUNK-SIZE] [--] <type> <username> <hostname> <database>


# runuser -u nextcloud -- nextcloud-occ db:convert-type --all-apps mysql nextcloud localhost nextcloud
What is the database password?
Creating schema in new database

In Connection.php line 85:
                                                                                                                                                                       
  Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [1045] Access denied for user 'nextcloud'@'localhost' (using password: YES)  
                                                                                                                                                                       

db:convert-type [--port PORT] [--password PASSWORD] [--clear-schema] [--all-apps] [--chunk-size CHUNK-SIZE] [--] <type> <username> <hostname> <database>

Looks like at some point you were using mysql instead of mariadb perhaps? What happens if you change the authentication plugin from auth_socket to unix_socket? Also, do you run mysql_upgrade after you upgrade major versions of mariadb?

Just a few guess… let me know if any of that helps, or if any of that isn’t clear.

Hosted by Flying Circus.