Nextcloud is unable to connect external msyql DB

Team,

We need to point out our nextcloud (11.0.2) application to external mysql DB from local mysql DB. we tried pointing to external mysql db, we are getting this below error.

[Wed Dec 20 11:35:11 2017] [error] [client 10.216.36.222] PHP Fatal error: Uncaught exception ‘Doctrine\DBAL\DBALException’ with message ‘Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2013] Lost connection to MySQL server at ‘reading initial communication packet’, system error: 111’ in /opt/hubzudoc/nextcloud/lib/private/DB/Connection.php:61\nStack trace:\n#0 /opt/hubzudoc/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\DB\Connection->connect()\n#1 /opt/hubzudoc/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\DBAL\Connection->getDatabasePlatformVersion()\n#2 /opt/hubzudoc/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\DBAL\Connection->detectDatabasePlatform()\n#3 /opt/hubzudoc/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\DBAL\Connection->getDatabasePlatform()\n#4 /opt/hubzudoc/nextcloud/lib/private/DB/Connection.php(148): Doctrine\DBAL\Connection->setTransactionIsolation(2)\n#5 /opt/hubzudoc/nextcloud/3rdparty/doctrine/dbal/ in /opt/hubzudoc/nextcloud/lib/private/DB/Connection.php on line 61

And we tried upgrading to 12.0.4 nextcloud and again tried to connect to external mysql DB but no luck, its showing same error. Could you please assit in fixing this issue.

Is the connection working when connecting via commandline from the machine nextcloud is running on?

Thanks Thomas for your response. we are able to telnet successfully but nextcloud application is throwing this error. Problem here, we noticed that application is not able to connect to DB, if nextcloud DB created in DB where other DB instances are running (replication are enabled). We were able to connect if we create nextcloud DB in one the DB where replication is not enabled. Could you please suggest.

Can other php applications connect to this database?

Could you elaborate on that? Also, the initial setup routine works?

Thomas,

Our DBA administrator provided DB for nextcloud application from where in some other DB instances are running (please note these db instances for some other application). what I meant to say is database server running multiple instances and he has setup replication between our DC and DR datacenter for other DB instances. If application tries to connect, we were seeing this exception. We tested with a other DB for nextcloud where replication is not enabled, application able to connect successfully. Not sure whats happening. Please suggest

Hi Hassan.

Well it sounds to me like the probem is the db infrastructure, no?

cheers
t.

Thanks @Thomas_Stein for your reply. We dont want you use a separate DB for nextcloud. How we can achieve it and by looking at exception, would you able to suggest any thing. Does next cloud require its own DB?

Its own Database Server: no. Its own Database: yes.

@Thomas_Stein

what i meant is, does next cloud application require a dedicated database (DB) mysql server? can’t we use a db for nextcloud from existing DB where some other DB instances are running. can you able to tell what could be the problem.

sure you can use a existing database server. Try connecting with the mysql Client, maybe the credentials are not setup correctly (locally or on the DB server). Also if you nextcloud on a Centos/RHEL server please check for selinux errors. Per default selinux do not allow the http server to connect via network to a DB server. This can be allowed by a boolean. audit2allow is your friend.

It is very likely you’ve not granted the database user permissions to access the database from another network location.

Can you authenticate from the CLI of the Nextcloud server with:

mysql -u username -h ip.address -puserpw

If not, that’s your problem.

Absolutely not. Only a dedicated DB.

@ksteinb

We are running php in amazon EC2 instance. when i try to run this command “semanage port -l | grep -w http_port_t”(command to view the ports SELinux allows httpd to listen on) am getting “SELinux policy is not managed or store cannot be accessed”. seems like SELinux is not enable on my ec2 instance. if it is not enabled i dont think its because of selinux security policy. I verified by running sestatus command its says “SELinux status: disabled” :smile:.

@JasonBayton

i tried authenticating by installing mysql client on nextcloud server, i was able to authenticate successfully. seems like its not database user permission issue :smile:.

Hmm, and that was with the nextcloud db user, not root/admin mysql account right?

@JasonBayton

Yes. its nextcloud db user. what next, please suggest. @ksteinb

Did you Check if an necessary PHP components are installed?

Sincerely,
Klaus

Von Samsung-Tablet gesendet

@ksteinb

Thanks for your response.
Please suggest what all php components need be installed. Please note that, nextcloud application work fines from local mysql DB server or from dedicated mysql DB server, this means all the components in place right. problem occurs when application try to connect nexctcloud db created in one of our existing mysql DB server (where some other db instances are running). @JasonBayton

@ksteinb @JasonBayton

Please update.

  • Did you try to do a packet trace?
  • Would the connection be redirected to another unreachable DB Server?
    Sorry I’m not involved with replicated DB’s

I’d also create an issue,