Nextcloud and MySQL oc_admin password mismatch

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 (eg, 20.0.11): 20.0.11
Operating system and version (eg, Solaris 11.4): Solaris 11.4
Apache or nginx version (eg, Apache 2.4.25): 2.4.48
PHP version (eg, 7.4): 7.3

The issue you are facing:

Nextcloud fails to run unless I run mysql with skip-grant-tables

Is this the first time you’ve seen this error? (Y/N):N
1st happened earlier this year, I tweaked the my.cnf and forgot about it :frowning:

Steps to replicate it:

  1. Run/restart mysql without skip-grant-tables in my.cnf

The output of your Nextcloud log in Admin > Logging:

{"reqId":"zjMD3ipUOUEVAarnZSk9","level":3,"time":"2021-11-11T12:17:12+00:00","remoteAddr":"82.47.37.5","user":"--","app":"index","method":"GET","url":"/nextcloud/index.php/apps/files/?dir=/Pictures&fileid=15243","message":{"Exception":"Doctrine\\DBAL\\DBALException","Message":"Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'oc_admin'@'localhost' (using password: YES)","Code":0,"Trace":[{"file":"/var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php"

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'passwordsalt' => 'fZnHTc2koNT5ARED0wfZo6dxvrtaIO',
  'secret' => 'rd8jImrCfEVM7frCcIJPafTgzETMAW4p7BtonY9WEKqoapBB',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    1 => '192.168.0.66',
    2 => '192.168.0.66:643',
    3 => 'ytc-cloud:643',
    4 => 'ytc1-cloud.dyndns.org:643',
    5 => 'ytc1.dyndns.org:643',
    6 => 'ytc-cloud:80',
  ),
  'datadirectory' => '/nextcloud/server/nextcloud/data',
  'overwrite.cli.url' => 'http://localhost',
  'dbtype' => 'mysql',
  'version' => '20.0.11.1',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'oc_admin',
  'dbpassword' => '*****removed******',
  'logtimezone' => 'UTC',
  'installed' => true,
  'instanceid' => 'oc798ms43svp',
  'loglevel' => 0,
  'mail_from_address' => '*******',
  'mail_smtpmode' => 'smtp',
  'mail_domain' => '*********',
  'auth.bruteforce.protection.enabled' => false,
  'theme' => '',
  'mail_sendmailmode' => 'smtp',
  'maintenance' => false,
  'mysql.utf8mb4' => false,
  'mail_smtpsecure' => 'tls',
  'mail_smtpauth' => 1,
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtphost' => 'mail.maui.co.uk',
  'mail_smtpport' => '587',
  'mail_smtpname' => '*******',
  'mail_smtppassword' => '********',
);

The output of your Apache/nginx/system log in /var/log/____:

[Thu Nov 11 12:44:18.868722 2021] [php7:error] [pid 11724] [client 192.168.0.4:53866] PHP Fatal error:  Uncaught Doctrine\\DBAL\\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'oc_admin'@'localhost' (using password: YES) in /var/www/nextcloud/lib/private/DB/Connection.php:72\nStack trace:\n#0 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(1449): OC\\DB\\Connection->connect()\n#1 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(892): Doctrine\\DBAL\\Connection->getWrappedConnection()\n#2 /var/www/nextcloud/lib/private/DB/Connection.php(202): Doctrine\\DBAL\\Connection->executeQuery('SELECT * FROM `...', Array, Array, NULL)\n#3 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php(206): OC\\DB\\Connection->executeQuery('SELECT * FROM `...', Array, Array)\n#4 /var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(248): Doctrine\\DBAL\\Query\\QueryBuilder->execute()\n#5 /var/www/nextcloud/lib/private/AppConfig.php(345): OC\\DB\\QueryBuilder\\QueryBuilder->execute()\n# in /var/www/nextcloud/lib/private/DB/Connection.php on line 72
[Thu Nov 11 12:44:18.880934 2021] [php7:error] [pid 23625] [client 192.168.0.4:53868] PHP Fatal error:  Uncaught Doctrine\\DBAL\\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'oc_admin'@'localhost' (using password: YES) in /var/www/nextcloud/lib/private/DB/Connection.php:72\nStack trace:\n#0 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(1449): OC\\DB\\Connection->connect()\n#1 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(892): Doctrine\\DBAL\\Connection->getWrappedConnection()\n#2 /var/www/nextcloud/lib/private/DB/Connection.php(202): Doctrine\\DBAL\\Connection->executeQuery('SELECT * FROM `...', Array, Array, NULL)\n#3 /var/www/nextcloud/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php(206): OC\\DB\\Connection->executeQuery('SELECT * FROM `...', Array, Array)\n#4 /var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(248): Doctrine\\DBAL\\Query\\QueryBuilder->execute()\n#5 /var/www/nextcloud/lib/private/AppConfig.php(345): OC\\DB\\QueryBuilder\\QueryBuilder->execute()\n# in /var/www/nextcloud/lib/private/DB/Connection.php on line 72
[Thu Nov 11 12:44:18.900479 2021] [php7:error] [pid 23998] [client 192.168.0.4:53870] PHP Fatal error:  Uncaught Error: Class 'OCA\\DAV\\Connector\\Sabre\\ExceptionLoggerPlugin' not found in /var/www/nextcloud/remote.php:61\nStack trace:\n#0 /var/www/nextcloud/remote.php(169): handleException(Object(Doctrine\\DBAL\\DBALException))\n#1 {main}\n  thrown in /var/www/nextcloud/remote.php on line 61

No clues or tips from anyone?
MySQL is not really my bag and need some guidance here please.

I’ve read a bit more, and looked at a few things and realise now it is more likely a GRANT issue.

—8<
mysql> show grants for oc_admin@localhost;
ERROR 1141 (42000): There is no such grant defined for user ‘oc_admin’ on host ‘localhost’
mysql> show grants for oc_admin @localhost;
ERROR 1141 (42000): There is no such grant defined for user ‘oc_admin’ on host ‘localhost’
mysql> GRANT ALL PRIVILEGES ON . TO ‘oc_admin’@localhost ;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> show grants for oc_admin @localhost;
ERROR 1141 (42000): There is no such grant defined for user ‘oc_admin’ on host ‘localhost’
—<

—8<
mysql> SELECT User, Host, authentication_string FROM mysql.user;
±--------------±----------±------------------------------------------+
| User | Host | authentication_string |
±--------------±----------±------------------------------------------+
| root | localhost | *8A71908A219AFBE6E08B7E5665A349537D05AFAB |
| root | ytc-cloud | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | NULL |
| | ytc-cloud | NULL |
| admin | localhost | *8A71908A219AFBE6E08B7E5665A349537D05AFAB |
| oc_admin | localhost | nqN3yhp2NdYReUFTApjjBwYsnOQfLA |
| oc_admin | % | nqN3yhp2NdYReUFTApjjBwYsnOQfLA |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
±--------------±----------±------------------------------------------+
11 rows in set (0.00 sec)
—8<

You are on the right track, the user has not enough permissions to access this database. I just got through some topics, can you try this?

GRANT ALL PRIVILEGES ON nextcloud.* TO 'oc_admin'@'localhost';

If you have phpmyadmin, you can comfortly click the permissions via an interface.

Aha !
And fixed
GRANT ALL PRIVILEGES ON ‘.’ TO ‘oc_admin’@% identified by ‘PASSWORD’;

That took some reading, found it here, MySQL :: Re: Error 11133(42000) , from back in 2009 !