MySql Connection Timeout After Migration to Digital Ocean Managed Database

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version: 17.0.9
Operating system and version: Ubuntu 16.04
Apache or nginx version: Apache 2.4.18
PHP version: 7.3.22

The issue you are facing:

NextCloud working fine for years on a Digital Ocean droplet with MySQL running on the same droplet. I’m migrating the MySQL database to a Digital Ocean Managed Database. When I configure NextCloud to use the Managed Database, the database connection times out.

As soon as I set the configuration back to the local MySQL server, it works fine again.

I can access the Managed Database from the droplet’s command line mysql client and from a PHP script using PDO_MYSQL running in another vhost on the same droplet.

I don’t have a lot of experience with DO Managed Databases, but it sure seems like this must be something simple. Got any troubleshooting suggestions?

Thanks!

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

Steps to replicate it:

  1. Starting from my working NextCloud installation.
  2. Migrate the database:
sudo -u www-data php7.3 occ maintenance:mode --on
mysqldump --no-tablespaces --default-character-set=utf8mb4 -u nextcloud -p'...' nextcloud | mysql -u sbw_nextcloud -p'...' -h db-mysql-...-0.a.db.ondigitalocean.com -P 25060 -D sbw_nextcloud
  1. Reconfigure as follows:
sudo -u www-data php7.3 occ config:import ~/nextclouddbmanaged.json

Here’s that JSON file:

{
    "system": {
        "dbname": "sbw_nextcloud",
        "dbhost": "db-mysql-...-0.a.db.ondigitalocean.com",
        "dbport": "25060",
        "dbuser": "sbw_nextcloud",
        "dbpassword": "..."
    }
}
  1. Note the web site is unresponsive, and this command (for example) throws an exception:
sudo -u www-data php7.3 occ user:list

Here’s the exception:

Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] Connection timed out in /.../lib/private/DB/Connection.php:64

I’ve also tried editing config.php directly. Same result: An occ command fails in the same way, and the web site is unresponsive.

After I manually change config.php back to the local MySQL server, all is back to normal.

The output of your Nextcloud log in Admin > Logging: None

The output of sudo -u www-data php7.3 occ config:list:

{
    "system": {
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "n.sbw.org"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "overwrite.cli.url": "https:\/\/n.sbw.org",
        "dbtype": "mysql",
        "version": "17.0.9.2",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "maintenance": false,
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpmode": "smtp",
        "mail_smtpauthtype": "LOGIN",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "theme": "",
        "loglevel": 2,
        "logtimezone": "America\/Los_Angeles",
        "mail_smtpsecure": "ssl",
        "mail_smtpauth": 1,
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "465",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "memcache.local": "\\OC\\Memcache\\APCu",
        "memcache.distributed": "\\OC\\Memcache\\Memcached",
        "memcached_servers": [
            [
                "localhost",
                11211
            ]
        ],
        "htaccess.RewriteBase": "\/",
        "updater.release.channel": "stable",
        "app_install_overwrite": [
            "calendar",
            "spreed"
        ],
        "jpeg_quality": "60",
        "preview_max_x": "2048",
        "preview_max_y": "2048",
        "mail_sendmailmode": "smtp"
    },
    "apps": {
        "accessibility": {
            "enabled": "yes",
            "installed_version": "1.3.0",
            "types": ""
        },
        "activity": {
            "enabled": "yes",
            "installed_version": "2.10.1",
            "types": "filesystem"
        },
        "audioplayer": {
            "enabled": "no",
            "installed_version": "2.6.0",
            "types": "filesystem"
        },
        "backgroundjob": {
            "lastjob": "1"
        },
        "bruteforcesettings": {
            "enabled": "yes",
            "installed_version": "1.6.0",
            "types": ""
        },
        "calendar": {
            "enabled": "yes",
            "installed_version": "2.0.4",
            "types": ""
        },
        "cloud_federation_api": {
            "enabled": "yes",
            "installed_version": "1.0.0",
            "types": "filesystem"
        },
        "comments": {
            "enabled": "yes",
            "installed_version": "1.7.0",
            "types": "logging"
        },
        "contacts": {
            "enabled": "yes",
            "installed_version": "3.3.0",
            "types": ""
        },
        "core": {
            "backgroundjobs_mode": "cron",
            "enterpriseLogoChecked": "yes",
            "installed.bundles": "[\"CoreBundle\"]",
            "installedat": "1505069399.1728",
            "lastcron": "1601259602",
            "lastupdateResult": "{\"version\":\"18.0.9.1\",\"versionstring\":\"Nextcloud 18.0.9\",\"url\":\"https:\\\/\\\/download.nextcloud.com\\\/server\\\/releases\\\/nextcloud-18.0.9.zip\",\"web\":\"https:\\\/\\\/docs.nextcloud.com\\\/server\\\/18\\\/admin_manual\\\/maintenance\\\/upgrade.html\",\"changes\":\"https:\\\/\\\/updates.nextcloud.com\\\/changelog_server\\\/?version=18.0.9\",\"autoupdater\":\"1\",\"eol\":\"0\"}",
            "lastupdatedat": "1601258991",
            "moveavatarsdone": "yes",
            "oc.integritycheck.checker": "[]",
            "previewsCleanedUp": "1",
            "public_files": "files_sharing\/public.php",
            "public_webdav": "dav\/appinfo\/v1\/publicwebdav.php",
            "scss.variables": "b61b4e68ecb9d338b532dcf8bf5ac9ca",
            "shareapi_allow_public_upload": "yes",
            "shareapi_default_expire_date": "yes",
            "shareapi_expire_after_n_days": "14",
            "theming.variables": "b61b4e68ecb9d338b532dcf8bf5ac9ca",
            "umgmt_show_backend": "false",
            "umgmt_show_email": "false",
            "umgmt_show_last_login": "false",
            "umgmt_show_storage_location": "false",
            "updater.secret.created": "1601061515",
            "vendor": "nextcloud"
        },
        "dav": {
            "buildCalendarReminderIndex": "yes",
            "buildCalendarSearchIndex": "yes",
            "chunks_migrated": "1",
            "enabled": "yes",
            "installed_version": "1.13.0",
            "regeneratedBirthdayCalendarsForYearFix": "yes",
            "types": "filesystem"
        },
        "deck": {
            "enabled": "no",
            "installed_version": "0.6.1",
            "types": "dav"
        },
        "dicomviewer": {
            "enabled": "yes",
            "installed_version": "1.2.2",
            "types": ""
        },
        "federatedfilesharing": {
            "enabled": "yes",
            "installed_version": "1.7.0",
            "types": ""
        },
        "federation": {
            "enabled": "yes",
            "installed_version": "1.7.0",
            "types": "authentication"
        },
        "files": {
            "cronjob_scan_files": "500",
            "enabled": "yes",
            "installed_version": "1.12.0",
            "types": "filesystem"
        },
        "files_antivirus": {
            "av_cmd_options": "",
            "av_host": "",
            "av_infected_action": "only_log",
            "av_max_file_size": "-1",
            "av_mode": "executable",
            "av_path": "\/usr\/bin\/clamscan",
            "av_port": "0",
            "av_socket": "\/var\/run\/clamav\/clamd.ctl",
            "av_stream_max_length": "10485760",
            "enabled": "no",
            "installed_version": "2.2.1",
            "types": "filesystem,dav"
        },
        "files_external": {
            "enabled": "yes",
            "installed_version": "1.8.0",
            "types": "filesystem"
        },
        "files_external_gdrive": {
            "enabled": "no",
            "installed_version": "0.2.8",
            "types": "filesystem"
        },
        "files_markdown": {
            "enabled": "no",
            "installed_version": "2.2.0",
            "types": ""
        },
        "files_pdfviewer": {
            "enabled": "yes",
            "installed_version": "1.6.0",
            "types": ""
        },
        "files_rightclick": {
            "enabled": "yes",
            "installed_version": "0.15.1",
            "types": ""
        },
        "files_sharing": {
            "enabled": "yes",
            "installed_version": "1.9.0",
            "types": "filesystem"
        },
        "files_texteditor": {
            "enabled": "no",
            "installed_version": "2.8.0",
            "types": ""
        },
        "files_trashbin": {
            "enabled": "yes",
            "installed_version": "1.7.0",
            "types": "filesystem,dav"
        },
        "files_versions": {
            "enabled": "yes",
            "installed_version": "1.10.0",
            "types": "filesystem,dav"
        },
        "files_videoplayer": {
            "enabled": "yes",
            "installed_version": "1.6.0",
            "types": ""
        },
        "firstrunwizard": {
            "enabled": "yes",
            "installed_version": "2.6.0",
            "types": "logging"
        },
        "gallery": {
            "enabled": "yes",
            "installed_version": "18.4.0",
            "types": ""
        },
        "gpxpod": {
            "enabled": "yes",
            "installed_version": "4.2.2",
            "reset304": "1",
            "resetPics404": "1",
            "types": ""
        },
        "logreader": {
            "enabled": "yes",
            "installed_version": "2.2.0",
            "types": ""
        },
        "lookup_server_connector": {
            "enabled": "yes",
            "installed_version": "1.5.0",
            "types": "authentication"
        },
        "mail": {
            "enabled": "no",
            "installed_version": "0.8.2",
            "types": ""
        },
        "nextcloud_announcements": {
            "enabled": "no",
            "installed_version": "1.6.0",
            "pub_date": "Thu, 24 Oct 2019 00:00:00 +0200",
            "types": "logging"
        },
        "notifications": {
            "enabled": "yes",
            "installed_version": "2.5.0",
            "types": "logging"
        },
        "oauth2": {
            "enabled": "yes",
            "installed_version": "1.5.0",
            "types": "authentication"
        },
        "password_policy": {
            "enabled": "yes",
            "enforceHaveIBeenPwned": "1",
            "installed_version": "1.7.0",
            "types": ""
        },
        "phonetrack": {
            "enabled": "yes",
            "installed_version": "0.6.4",
            "types": ""
        },
        "preview": {
            "jpeg_quality": "60"
        },
        "previewgenerator": {
            "heightSizes": "256",
            "squareSizes": "32 256",
            "widthSizes": "256 384"
        },
        "privacy": {
            "enabled": "no",
            "installed_version": "1.0.0",
            "types": ""
        },
        "provisioning_api": {
            "enabled": "yes",
            "installed_version": "1.7.0",
            "types": "prevent_group_restriction"
        },
        "recommendations": {
            "enabled": "no",
            "installed_version": "0.4.0",
            "types": ""
        },
        "richdocuments": {
            "enabled": "no",
            "installed_version": "3.7.3",
            "types": "filesystem,dav,prevent_group_restriction",
            "wopi_url": "https:\/\/collabora.sbw.org"
        },
        "serverinfo": {
            "enabled": "yes",
            "installed_version": "1.7.0",
            "types": ""
        },
        "sharebymail": {
            "enabled": "yes",
            "installed_version": "1.7.0",
            "types": "filesystem"
        },
        "spreed": {
            "conversations_files_public_shares": "0",
            "enabled": "yes",
            "installed_version": "7.0.4",
            "project_access_invalidated": "1",
            "signaling_ticket_secret": "***REMOVED SENSITIVE VALUE***",
            "stun_servers": "***REMOVED SENSITIVE VALUE***",
            "types": "prevent_group_restriction"
        },
        "support": {
            "SwitchUpdaterServerHasRun": "yes",
            "enabled": "no",
            "installed_version": "1.0.2",
            "types": "session"
        },
        "survey_client": {
            "enabled": "no",
            "installed_version": "1.5.0",
            "last_report": "{\"id\":\"oc4h4t9q2zg2\",\"items\":[[\"server\",\"version\",\"17.0.6.2\"],[\"server\",\"code\",\"other\"],[\"server\",\"enable_avatars\",\"yes\"],[\"server\",\"enable_previews\",\"yes\"],[\"server\",\"memcache.local\",\"\\\\OC\\\\Memcache\\\\APCu\"],[\"server\",\"memcache.distributed\",\"\\\\OC\\\\Memcache\\\\Memcached\"],[\"server\",\"asset-pipeline.enabled\",\"no\"],[\"server\",\"filelocking.enabled\",\"yes\"],[\"server\",\"memcache.locking\",\"none\"],[\"server\",\"debug\",\"no\"],[\"server\",\"cron\",\"cron\"],[\"php\",\"version\",\"7.3.17\"],[\"php\",\"memory_limit\",-1],[\"php\",\"max_execution_time\",0],[\"php\",\"upload_max_filesize\",2097152],[\"database\",\"type\",\"mysql\"],[\"database\",\"version\",\"5.7.30\"],[\"database\",\"size\",80084992],[\"apps\",\"accessibility\",\"1.3.0\"],[\"apps\",\"activity\",\"2.10.1\"],[\"apps\",\"audioplayer\",\"disabled\"],[\"apps\",\"bruteforcesettings\",\"1.6.0\"],[\"apps\",\"calendar\",\"2.0.3\"],[\"apps\",\"cloud_federation_api\",\"1.0.0\"],[\"apps\",\"comments\",\"1.7.0\"],[\"apps\",\"contacts\",\"3.3.0\"],[\"apps\",\"dav\",\"1.13.0\"],[\"apps\",\"deck\",\"disabled\"],[\"apps\",\"dicomviewer\",\"1.2.2\"],[\"apps\",\"federatedfilesharing\",\"1.7.0\"],[\"apps\",\"federation\",\"1.7.0\"],[\"apps\",\"files\",\"1.12.0\"],[\"apps\",\"files_antivirus\",\"disabled\"],[\"apps\",\"files_external\",\"1.8.0\"],[\"apps\",\"files_external_gdrive\",\"disabled\"],[\"apps\",\"files_markdown\",\"disabled\"],[\"apps\",\"files_pdfviewer\",\"1.6.0\"],[\"apps\",\"files_rightclick\",\"0.15.1\"],[\"apps\",\"files_sharing\",\"1.9.0\"],[\"apps\",\"files_texteditor\",\"disabled\"],[\"apps\",\"files_trashbin\",\"1.7.0\"],[\"apps\",\"files_versions\",\"1.10.0\"],[\"apps\",\"files_videoplayer\",\"1.6.0\"],[\"apps\",\"firstrunwizard\",\"2.6.0\"],[\"apps\",\"gallery\",\"18.4.0\"],[\"apps\",\"gpxpod\",\"4.2.1\"],[\"apps\",\"logreader\",\"2.2.0\"],[\"apps\",\"lookup_server_connector\",\"1.5.0\"],[\"apps\",\"mail\",\"disabled\"],[\"apps\",\"nextcloud_announcements\",\"1.6.0\"],[\"apps\",\"notifications\",\"2.5.0\"],[\"apps\",\"oauth2\",\"1.5.0\"],[\"apps\",\"password_policy\",\"1.7.0\"],[\"apps\",\"phonetrack\",\"0.6.2\"],[\"apps\",\"privacy\",\"disabled\"],[\"apps\",\"provisioning_api\",\"1.7.0\"],[\"apps\",\"recommendations\",\"disabled\"],[\"apps\",\"richdocuments\",\"3.5.3\"],[\"apps\",\"serverinfo\",\"1.7.0\"],[\"apps\",\"sharebymail\",\"1.7.0\"],[\"apps\",\"spreed\",\"7.0.3\"],[\"apps\",\"support\",\"1.0.1\"],[\"apps\",\"survey_client\",\"1.5.0\"],[\"apps\",\"systemtags\",\"1.7.0\"],[\"apps\",\"tasks\",\"0.12.2\"],[\"apps\",\"text\",\"disabled\"],[\"apps\",\"theming\",\"1.8.0\"],[\"apps\",\"twofactor_backupcodes\",\"1.6.0\"],[\"apps\",\"twofactor_nextcloud_notification\",\"2.3.0\"],[\"apps\",\"twofactor_totp\",\"4.1.3\"],[\"apps\",\"updatenotification\",\"1.7.0\"],[\"apps\",\"viewer\",\"1.2.0\"],[\"apps\",\"weather\",\"disabled\"],[\"apps\",\"workflowengine\",\"1.7.0\"],[\"stats\",\"num_files\",127544],[\"stats\",\"num_users\",8],[\"stats\",\"num_storages\",13],[\"stats\",\"num_storages_local\",2],[\"stats\",\"num_storages_home\",9],[\"stats\",\"num_storages_other\",2],[\"stats\",\"num_comments\",181],[\"stats\",\"num_comment_markers\",7],[\"stats\",\"num_systemtags\",0],[\"stats\",\"num_systemtags_mappings\",0],[\"files_sharing\",\"num_shares\",35],[\"files_sharing\",\"num_shares_user\",5],[\"files_sharing\",\"num_shares_groups\",3],[\"files_sharing\",\"num_shares_link\",26],[\"files_sharing\",\"num_shares_link_no_password\",26],[\"files_sharing\",\"num_fed_shares_sent\",0],[\"files_sharing\",\"num_fed_shares_received\",0],[\"files_sharing\",\"permissions_3_1\",\"20\"],[\"files_sharing\",\"permissions_3_3\",\"3\"],[\"files_sharing\",\"permissions_3_4\",\"3\"],[\"files_sharing\",\"permissions_1_17\",\"1\"],[\"files_sharing\",\"permissions_0_19\",\"1\"],[\"files_sharing\",\"permissions_0_31\",\"4\"],[\"files_sharing\",\"permissions_1_31\",\"2\"],[\"files_sharing\",\"permissions_2_31\",\"1\"],[\"encryption\",\"enabled\",\"no\"],[\"encryption\",\"default_module\",\"no\"]]}",
            "last_sent": "1589155503",
            "types": ""
        },
        "systemtags": {
            "enabled": "yes",
            "installed_version": "1.7.0",
            "types": "logging"
        },
        "tasks": {
            "enabled": "no",
            "installed_version": "0.13.1",
            "types": ""
        },
        "text": {
            "enabled": "no",
            "installed_version": "1.1.1",
            "types": ""
        },
        "theming": {
            "backgroundMime": "backgroundColor",
            "cachebuster": "11",
            "color": "#eeeeee",
            "enabled": "yes",
            "installed_version": "1.8.0",
            "logoMime": "image\/gif",
            "name": "sbw.org",
            "slogan": "***REMOVED SENSITIVE VALUE***",
            "types": "logging",
            "url": "***REMOVED SENSITIVE VALUE***"
        },
        "twofactor_backupcodes": {
            "enabled": "yes",
            "installed_version": "1.6.0",
            "types": ""
        },
        "twofactor_nextcloud_notification": {
            "enabled": "yes",
            "installed_version": "2.3.0",
            "sbw_enabled": "1",
            "types": ""
        },
        "twofactor_totp": {
            "enabled": "yes",
            "installed_version": "4.1.3",
            "types": ""
        },
        "updatenotification": {
            "audioplayer": "2.6.1",
            "bruteforcesettings": "1.6.0",
            "calendar": "2.0.4",
            "contacts": "3.3.0",
            "core": "18.0.9.1",
            "deck": "0.6.0",
            "dicomviewer": "1.2.1",
            "enabled": "yes",
            "files_markdown": "2.0.6",
            "files_pdfviewer": "1.1.2",
            "files_rightclick": "0.15.1",
            "gpxpod": "4.2.1",
            "installed_version": "1.7.0",
            "phonetrack": "0.6.4",
            "richdocuments": "3.7.4",
            "spreed": "7.0.4",
            "tasks": "0.13.1",
            "text": "1.0.2",
            "twofactor_nextcloud_notification": "2.3.0",
            "types": "",
            "update_check_errors": "0"
        },
        "viewer": {
            "enabled": "yes",
            "installed_version": "1.2.0",
            "types": ""
        },
        "weather": {
            "enabled": "no",
            "installed_version": "1.5.1",
            "openweathermap_api_key": "63cff5eb1b10d476a2baec3da2db217b",
            "types": ""
        },
        "workflowengine": {
            "enabled": "yes",
            "installed_version": "1.7.0",
            "types": "filesystem"
        }
    }
}

The output of your Apache log: Nothing relevant. Just a 500 error.

I resolved this by noting dbport no longer appears in config.sample.php, which says instead the port must be included in the dbhost config:

/**
 * Your host server name, for example ``localhost``, ``hostname``,
 * ``hostname.example.com``, or the IP address. To specify a port use
 * ``hostname:####``; to specify a Unix socket use
 * ``localhost:/path/to/socket``.
 */
'dbhost' => '',

Perhaps dbport was in my config.php because it was used in an earlier version of Nextcloud?

In any case, when I made that change to my config, it connected to the database correctly.

1 Like