Error when trying to convert / create a new database (Failed to connect to the database / connection refused)

Nextcloud version: 25.0.3
Operating system and version: Ubuntu 22.10
Apache or nginx version: nginx/1.20.2
PHP version: 8.0.25

I’m trying to convert the default sqlite database into a MariaDB one, but I receive an error after following the official instructions here.

I run the following command:

docker exec -it -u 1000 nextcloud /config/www/nextcloud/occ db:convert-type --password="mypassword" mysql admin 127.0.0.1 nextcloud

and I get the following output/error:

Creating schema in new database

In Connection.php line 139:
                                                                                                                     
Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] Connection refused  

This is a big red error. I get a similar error when I replace 'dbtype' => 'sqlite3', with 'dbtype' => 'mysql', in my config.php file, but that doesn’t have the red background, and it includes a stack trace.

Instead of 127.0.0.1 for the hostname I’ve also tried the hostname of the docker container (e3a072c2a674) and the hostname of the host machine. Both produce the same error.

config.php:

<?php
$CONFIG = array (
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'datadirectory' => '/data',
  'instanceid' => 'ocl6tephtekn',
  'passwordsalt' => '[redacted]',
  'secret' => '[redacted]',
  'overwriteprotocol' => 'https',
  'trusted_proxies' => ['172.64.0.0/13'],
  'default_phone_region' => 'US',
  'defaultapp' => 'files',
  'filesystem_check_changes' => 1,
  'trusted_domains' => 
  array (
    0 => '[redacted]',
  ),
  'dbtype' => 'sqlite3',
  'version' => '25.0.3.2',
  'overwrite.cli.url' => '[redacted]',
  'installed' => true,
);

As an additional question, I’d prefer to use MariaDB over mysql, but replacing mysql with maria (or mariadb/maria_db) in the occ command I’m running gives me an error, and the documentation isn’t super clear.

Don’t use 127.0.0.1 or localhost with Docker. Use the host IP, or the container name.

1 Like

I get the exact same error when using the docker container name.

I get a network unreachable error error when using the local IP (192.168.1.103)

$ docker exec -it -u 1000 nextcloud /config/www/nextcloud/occ db:convert-type --password="[redacted]" mysql admin 192.168.1.103 nextcloud
Creating schema in new database

In Connection.php line 139:
                                                                                                                      
Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] Network unreachable  

I also tried using the domain that points to my nextcloud instance, which give me a getaddrinfo failed error.

$ docker exec -it -u 1000 nextcloud /config/www/nextcloud/occ db:convert-type --password="[redacted] " mysql admin https://nextcloud.example.com nextcloud
Creating schema in new database

In Connection.php line 139:
                                                                                                                                            
Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Try again