Unable to convert nextcloud from sqlite3 to mariadb when both nextcloud and mariadb are running in linked docker containers

Nextcloud version Nextcloud Hub 5 (27.0.2)
Operating system and version docker
Apache or nginx version: Don’t know
PHP version: Don’t know

The issue you are facing: Would like to convert sqlite3 → mariadb

Trying to convert my nextcloud instance from sqlite3 → mariadb. Both nextcloud and mariadb are running as docker containers on Synology and they are linked. Going by Converting database type — Nextcloud latest Administration Manual latest documentation I do:

Jupiter:docker exec -itu 33 nextcloud bash
www-data@nextcloud:~/html$ php occ db:convert-type --all-apps mysql nextcloud localhost nextcloud
What is the database password?
Creating schema in new database

In Connection.php line 140:
                                                                               
  Failed to connect to the database: An exception occurred in the driver: SQL  
  STATE[HY000] [2002] No such file or directory                                
                                                                               

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

www-data@nextcloud:~/html$ 

Yet my mariadb container shows that there’s a nextcloud database:

Jupiter:docker exec -it mariadb mariadb -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 11.1.2-MariaDB-1:11.1.2+maria~ubu2204 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| nextcloud          |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.001 sec)

MariaDB [(none)]> 

The hostname to connection to your mariadb container from your nextcloud container will not be localhost generally.

From the looks of it you should specify mariadb instead of localhost.

If stuck post your entire Compose file.

I tried changing localhost to mariadb as that is the container name of my mariadb container. It prompted for database password and I supplied “nextcloud”'s database password. it said access was denied. Thinking that perhaps I had the wrong password for the nextcloud user I tried:

Jupiter:docker exec -it mariadb mariadb -unextcloud -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 11.1.2-MariaDB-1:11.1.2+maria~ubu2204 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

I gave it what I know of the nextcloud user’s password and I was able to get in. So it seems like the nextcloud user did not have enough permissions to do the needful. So I tried specifying “root” as the username and gave it the MariaDB root password. This seems to have worked but I fear I may have the incorrect user permissions on the db. How do I verify and how do I fix if needed?

www-data@nextcloud:~/html$ php occ db:convert-type --all-apps mysql root mariadb nextcloud
What is the database password?
Creating schema in new database
 - activity
 - admin_audit
 - bruteforcesettings
 - circles
 - cloud_federation_api
 - comments
 - contactsinteraction
 - dashboard
 - dav
 - encryption
 - federatedfilesharing
 - federation
 - files
 - files_external
 - files_pdfviewer
 - files_rightclick
 - files_sharing
 - files_trashbin
 - files_versions
 - firstrunwizard
 - logreader
 - lookup_server_connector
 - nextcloud_announcements
 - notifications
 - oauth2
 - password_policy
 - photos
 - privacy
 - provisioning_api
 - recommendations
 - related_resources
 - serverinfo
 - settings
 - sharebymail
 - support
 - survey_client
 - suspicious_login
 - systemtags
 - text
 - theming
 - twofactor_backupcodes
 - twofactor_totp
 - updatenotification
 - user_ldap
 - user_status
 - viewer
 - weather_status
 - workflowengine
 - oc_accounts
 2/2 [============================] 100% < 1 sec/< 1 sec
 - oc_accounts_data
 24/24 [============================] 100% < 1 sec/< 1 sec
 - oc_activity
chunked query, 5 chunks
 4490/4490 [============================] 100% 22 secs/22 secs
 - oc_activity_mq
    0 [>---------------------------] < 1 sec
 - oc_addressbookchanges
 6/6 [============================] 100% < 1 sec/< 1 sec
 - oc_addressbooks
 3/3 [============================] 100% < 1 sec/< 1 sec
 - oc_appconfig
 157/157 [============================] 100%  1 sec/1 sec 
 - oc_authorized_groups
    0 [>---------------------------] < 1 sec
 - oc_authtoken
 89/89 [============================] 100% 8 secs/8 secs
 - oc_bruteforce_attempts
 69/69 [============================] 100% < 1 sec/< 1 sec
 - oc_calendar_invitations
    0 [>---------------------------] < 1 sec
 - oc_calendar_reminders
    0 [>---------------------------] < 1 sec
 - oc_calendar_resources
    0 [>---------------------------] < 1 sec
 - oc_calendar_resources_md
    0 [>---------------------------] < 1 sec
 - oc_calendar_rooms
    0 [>---------------------------] < 1 sec
 - oc_calendar_rooms_md
    0 [>---------------------------] < 1 sec
 - oc_calendarchanges
    0 [>---------------------------] < 1 sec
 - oc_calendarobjects
    0 [>---------------------------] < 1 sec
 - oc_calendarobjects_props
    0 [>---------------------------] < 1 sec
 - oc_calendars
 6/6 [============================] 100%  1 sec/1 sec 
 - oc_calendarsubscriptions
    0 [>---------------------------] < 1 sec
 - oc_cards
 2/2 [============================] 100% < 1 sec/< 1 sec
 - oc_cards_properties
 9/9 [============================] 100%  1 sec/1 sec 
 - oc_circles_circle
 4/4 [============================] 100% < 1 sec/< 1 sec
 - oc_circles_event
 2/2 [============================] 100% < 1 sec/< 1 sec
 - oc_circles_member
 6/6 [============================] 100%  1 sec/1 sec 
 - oc_circles_membership
 5/5 [============================] 100% < 1 sec/< 1 sec
 - oc_circles_mount
    0 [>---------------------------] < 1 sec
 - oc_circles_mountpoint
    0 [>---------------------------] < 1 sec
 - oc_circles_remote
    0 [>---------------------------] < 1 sec
 - oc_circles_share_lock
    0 [>---------------------------] < 1 sec
 - oc_circles_token
    0 [>---------------------------] < 1 sec
 - oc_collres_accesscache
    0 [>---------------------------] < 1 sec
 - oc_collres_collections
    0 [>---------------------------] < 1 sec
 - oc_collres_resources
    0 [>---------------------------] < 1 sec
 - oc_comments
    0 [>---------------------------] < 1 sec
 - oc_comments_read_markers
    0 [>---------------------------] < 1 sec
 - oc_dav_cal_proxy
    0 [>---------------------------] < 1 sec
 - oc_dav_shares
    0 [>---------------------------] < 1 sec
 - oc_direct_edit
    0 [>---------------------------] < 1 sec
 - oc_directlink
 13/13 [============================] 100% < 1 sec/< 1 sec
 - oc_external_applicable
 2/2 [============================] 100% < 1 sec/< 1 sec
 - oc_external_config
 2/2 [============================] 100%  1 sec/1 sec 
 - oc_external_mounts
 2/2 [============================] 100% < 1 sec/< 1 sec
 - oc_external_options
 12/12 [============================] 100%  1 sec/1 sec 
 - oc_federated_reshares
    0 [>---------------------------] < 1 sec
 - oc_file_locks
chunked query, 29 chunks
 28484/28484 [============================] 100% 38 secs/38 secs
 - oc_file_metadata
chunked query, 3 chunks
 2120/2120 [============================] 100% 4 secs/4 secs
 - oc_filecache
chunked query, 35 chunks
 34150/34150 [============================] 100% 58 secs/58 secs
 - oc_filecache_extended
chunked query, 2 chunks
 1304/1304 [============================] 100% 3 secs/3 secs
 - oc_files_trash
 24/24 [============================] 100%  1 sec/1 sec 
 - oc_files_versions
chunked query, 3 chunks
 2624/2624 [============================] 100% 6 secs/6 secs
 - oc_flow_checks
    0 [>---------------------------] < 1 sec
 - oc_flow_operations
    0 [>---------------------------] < 1 sec
 - oc_flow_operations_scope
    0 [>---------------------------] < 1 sec
 - oc_group_admin
    0 [>---------------------------] < 1 sec
 - oc_group_user
 2/2 [============================] 100% < 1 sec/< 1 sec
 - oc_groups
 1/1 [============================] 100%  1 sec/1 sec 
 - oc_jobs
chunked query, 2 chunks
 1730/1730 [============================] 100% 15 secs/15 secs
 - oc_known_users
    0 [>---------------------------] < 1 sec
 - oc_login_flow_v2
    0 [>---------------------------] < 1 sec
 - oc_migrations
Skipping migrations table because it was already filled by running the migrations
 - oc_mimetypes
 50/50 [============================] 100% < 1 sec/< 1 sec
 - oc_mounts
 6/6 [============================] 100%  1 sec/1 sec 
 - oc_notifications
 7/7 [============================] 100% < 1 sec/< 1 sec
 - oc_notifications_pushhash
    0 [>---------------------------] < 1 sec
 - oc_notifications_settings
 2/2 [============================] 100% < 1 sec/< 1 sec
 - oc_oauth2_access_tokens
    0 [>---------------------------] < 1 sec
 - oc_oauth2_clients
    0 [>---------------------------] < 1 sec
 - oc_open_local_editor
 1/1 [============================] 100% < 1 sec/< 1 sec
 - oc_photos_albums
    0 [>---------------------------] < 1 sec
 - oc_photos_albums_collabs
    0 [>---------------------------] < 1 sec
 - oc_photos_albums_files
    0 [>---------------------------] < 1 sec
 - oc_preferences
 53/53 [============================] 100%  1 sec/1 sec 
 - oc_privacy_admins
    0 [>---------------------------] < 1 sec
 - oc_profile_config
 1/1 [============================] 100% < 1 sec/< 1 sec
 - oc_properties
    0 [>---------------------------] < 1 sec
 - oc_ratelimit_entries
    0 [>---------------------------] < 1 sec
 - oc_reactions
    0 [>---------------------------] < 1 sec
 - oc_recent_contact
    0 [>---------------------------] < 1 sec
 - oc_schedulingobjects
    0 [>---------------------------] < 1 sec
 - oc_share
 20/20 [============================] 100% < 1 sec/< 1 sec
 - oc_share_external
    0 [>---------------------------] < 1 sec
 - oc_storages
 6/6 [============================] 100%  1 sec/1 sec 
 - oc_storages_credentials
 1/1 [============================] 100% < 1 sec/< 1 sec
 - oc_systemtag
 2/2 [============================] 100% < 1 sec/< 1 sec
 - oc_systemtag_group
    0 [>---------------------------] < 1 sec
 - oc_systemtag_object_mapping
 19/19 [============================] 100% < 1 sec/< 1 sec
 - oc_text_documents
 11/11 [============================] 100%  1 sec/1 sec 
 - oc_text_sessions
 5/5 [============================] 100% < 1 sec/< 1 sec
 - oc_text_steps
 22/22 [============================] 100%  1 sec/1 sec 
 - oc_trusted_servers
    0 [>---------------------------] < 1 sec
 - oc_twofactor_backupcodes
    0 [>---------------------------] < 1 sec
 - oc_twofactor_providers
 2/2 [============================] 100% < 1 sec/< 1 sec
 - oc_user_status
 2/2 [============================] 100%  1 sec/1 sec 
 - oc_user_transfer_owner
    0 [>---------------------------] < 1 sec
 - oc_users
 2/2 [============================] 100% < 1 sec/< 1 sec
 - oc_vcategory
    0 [>---------------------------] < 1 sec
 - oc_vcategory_to_object
    0 [>---------------------------] < 1 sec
 - oc_webauthn
    0 [>---------------------------] < 1 sec
 - oc_whats_new
 1/1 [============================] 100% < 1 sec/< 1 sec
www-data@nextcloud:~/html$ 

Hmmm… I was worried about restarting the nextcloud container and it not working because I did this as root but it seems to have worked. If there’s anything else I need to do to make sure this is correct let me know.

My best guess is when you created the nextcloud db user that the @hostname part was localhost or something like that rather than a wildcard (%) or the nextcloud container’s hostname/IP address.

https://mariadb.com/kb/en/create-user/#account-names

Sounds right.

Jupiter:docker exec -it mariadb mariadb -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 663
Server version: 11.1.2-MariaDB-1:11.1.2+maria~ubu2204 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> select user, host from user;
+-------------+-----------+
| User        | Host      |
+-------------+-----------+
| root        | %         |
| healthcheck | 127.0.0.1 |
| healthcheck | ::1       |
| healthcheck | localhost |
| mariadb.sys | localhost |
| nextcloud   | localhost |
| root        | localhost |
+-------------+-----------+
7 rows in set (0.001 sec)

MariaDB [mysql]>  

So is my installation incorrect? How do I correct it? I mean it seems like right now Nextcloud is using MariaDB but as the root user. Shouldn’t it be as the nextcloud user?

It’s not ideal, correct.

Maybe put Nextcloud Server into maintenance mode then change things:

occ maintenance:mode --on

Probably:

CREATE USER 'nextcloud'@'%' IDENTIFIED BY 'password';

or

CREATE USER 'nextcloud'@'nextcloud' IDENTIFIED BY 'password';

Depending on how restrictive your preference is.

Followed by:

GRANT ALL PRIVILEGES ON nextcloud.* TO 'username'@'%';

or

GRANT ALL PRIVILEGES ON nextcloud.* TO 'username'@'nextcloud';

Wrapped up with a:

FLUSH PRIVILEGES

Then update your Nextcloud config.php to point at your MariaDB/MySQL database using the correct dbuser.

Finally, turn off maintenance mode:

occ maintenance:mode --off

I had a nextcloud user and he was granted access to localhost but I’m now realizing that mariadb, running in another docker container, is like running in another host thus the requirement for ‘%’ in the hostname. Added that.

MariaDB [(none)]> select user,host from mysql.user;
+-------------+-----------+
| User        | Host      |
+-------------+-----------+
| nextcloud   | %         |
| root        | %         |
| healthcheck | 127.0.0.1 |
| healthcheck | ::1       |
| healthcheck | localhost |
| mariadb.sys | localhost |
| nextcloud   | localhost |
| root        | localhost |
+-------------+-----------+
8 rows in set (0.002 sec)

MariaDB [(none)]> 

Changed dbuser and password and things look good. Thanks.

1 Like