SQLSTATE[HY000] [1045] Access denied for user 'oc_admin'@'' (using password: YES)


Nextcloud setup is driving me crazy! Problem is the following message when I go through the setup wizard:

Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'oc_admin'@'' (using password: YES) 


I had it working an then it went haywire. See this post.
The oc_admin-user did not have the privileges to DROP DATABASE. With the root-user I couldn’t grant the privileges no matter how hard I tried. Hence I couldn’t delete database content and went for the nuclear option: deleting config and reinstalling from scratch.


Everything is dockerised and at the latest releases. Below my docker-compose file for nextcloud and mariadb the #-sign is to go to a “minimal” working example at which I have not arrived yet. (Allthough, before it went haywire, everything worked like charm when uncommented.)

    image: linuxserver/nextcloud
    container_name: nextcloud
        - PUID=48
        - PGID=100
        - TZ=${TIMEZONE}
        - /var/hda/files/nextcloud/config:/config
        - /var/hda/files/nextcloud/data:/data
        - /var/hda/files/Docs:/var/hda/files/Docs
        - /var/hda/files/Pictures:/var/hda/files/Pictures
        - /var/hda/files/Music:/var/hda/files/Music
    # networks:
        # - default
        # - traefik_proxy
        - 7300:443
        - "mariadb"
    restart: unless-stopped

    image: linuxserver/mariadb
    container_name: mariadb
    # networks:
        # - default
        # - traefik_proxy
        - MYSQL_ROOT_USER=root
     # - MYSQL_DATABASE=nextcloud
         - PUID=48
         - PGID=100
         - TZ=${TIMEZONE}
         - /var/hda/files/mariadb/config:/config
        - 3307:3306
    restart: unless-stopped

When I understand everything correctly there shouldn’t be any compatibility issues.

Details and solutions tried:

  • The connection to the mariadb with the root-user works: When installing mariadb from scratch, I can login and check for already created databases. Once I click finish installation in the setup wizard, the database nextcloud is created (as I entered in the respective field).

  • So the problem seems that root cannot create the oc_admin-user allthough it can access mysql and create the database

So far I tried:

  • Manually creating the oc_admin-user and grant respective privileges (one of the solutions suggested in forums). No use: Nextcloud tries to create oc_admin1 with the same issues.

Any ideas? Seriously, it’s driving me nuts - I already spent hours (literaly) trying to solve the problem.

Thank you!

the documentation of the linuxserver.io mariadb container says you should create database and credentials via:

      - MYSQL_USER=MYSQL_USER #optional

no root user needed. normally.

why? do you want to access your db from everywhere?

Thank you very much! This helped!

I have the same problem again.

I am using LibreElec and run Docker Containers from Linuxserver.io which LE provides with a wrapper as easy installable addons. MariaDB is already up and running and KODI is successfully storing the movie data there.
Now I installed nextcloud 10 from Linuxserver.io and call the web gui 1st time to configure nextcloud. I had prepared the db user and db in the bash of the container with the SQL commands.
But when I try to create user admin with the entries for a “MySQL/MariaDB” I get the error back "SQLSTATE[HY000] [1045] Access denied for user ‘oc_admin’@‘’ "

Creating the nextcloud DB in the docker start command is not an option for me because the DBMS is used for several apps and hold already lot of data…

One year ago with earlier version of nextcloud I could manage to setup in this way, now not anymore. What can be the reason?

Any idea someone ?

I have exactly the same problem on my Synology.

I try many times. I can connect to the db with phpMyAdmin, I see an empty database nextcloud.

Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'oc_admin'@'localhost' (using password: YES)

No idea why is not able to create the user.

My platform is a Synology DSM 6.2

Any ideas?

in the end I made it !
it looks as the V18 is still not completely free of temporary developers hacks :slight_smile:

I looked into config.php and saw the it has fixed values that come not from my input in the 1st use at the login page but which seem to be hard wired ! Look yourself, you will find something like :

‘dbname’ => ‘ncdb’,
‘dbhost’ => ‘xxxxxxxxxxxxxxxxx:3306’,
‘dbport’ => ‘’,
‘dbtableprefix’ => ‘oc_’,
‘mysql.utf8mb4’ => true,
‘dbuser’ => ‘oc_admin’,
‘dbpassword’ => ‘xxxxxxxxxxxxxxxxxxx’,

Your individual values replace xxxxxxxxx, I created user and db like this (Password is oc_admin) before I started the web guide 1st time and now it works!

let me understand, you created the db and user manualy ?
but you put directly the password in the config or is encrypted, like is doing in the script?


Yes, I created the user/password and the db manually in MariaDB (using “DBeaver”) AND used the same in the web-gui 1st access. I guess that the content of config.php was created at setup including the encrypted Password (“hard-wired”). check your config.php content !

I found the file and I try to create the user on MariaDB manually (command line), an empty database has already created. Doing that, running again the setup I get the same error message trying to create a second user:

Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'oc_admin1'@'localhost' (using password: YES)

I also try to install a precedent version of nextcloud, no way. It doesn’t works.

It is really hard do figure out what is wrong.

The solution seams to be:

Here adapted for DSM 6.2

sudo /usr/local/mariadb10/bin/mysql --user=root --password=sadKS3f_z5sif nextcloud
create database nextcloud;
create user nxtcloudadmin@localhost identified by ‘admin123’;
grant all privileges on nextcloud.* to nxtcloudadmin@localhost identified by ‘admin123’;
flush privileges;

sudo nano /etc/mysql/my.cnf

add these lines at the bottom:

log-bin = /var/log/mysql/mariadb-bin
log-bin-index = /var/log/mysql/mariadb-bin.index
binlog_format = mixed

sudo mkdir /var/log/mysql/
sudo chmod 777 /var/log/mysql/

Goes tu packet center, search mariadb stop and restart.

Then try the wizard again where you use:
Username: skycorp
Password: skycorp_password
Database user: nxtcloudadmin
Database password: admin123
Database name: nextcloud
Database host: localhost

And don’t forget to change admin123 into a real password.


I tried many things, read many tips, until I figured it out.

My steps:
Install Apache with php.
Install MariaDB and secure it with:
sudo mysql_secure_installation
(That gives a password to the root account.)
Added the lines at the bottom of my.conf.
Installed phpMyAdmin.
Needed to do a
sudo mySQL
update mysql.user set plugin = ‘mysql_native_password’ where user=‘root’
otherwise I couldn’t log in.
(hindsight: Probably was a mistake. I should have logged in to phpMyAdmin as user phpmyadmin, not as root)
Then phpMySQL was up and running.
Then installed nextcloud and run into the often described problem.

One needs to understand, on the first configuration screen:
“User name” and corresponding password are for a future admin user of NextCloud.
“Database user” and corresponding password are NOT root, but a nextcloud-internal user that is used to access the database.
Use phpMyAdmin to create the “Database user” with password. Grant all privileges on the database. Means: select the database, then privileges, new user …
To be sure, in the next step select that new user and give him also the grant rights on that database. Maybe not needed, but I saw it in several solutions.
Then edit the nextcloud/config/config.php file.
dbuser: Database user
dbpassword: the password of the Database user in clear text (i.e. not encrypted).
And voila, enter the data at the initial config screen, and it works.

I fixed the config.php as your solution,but it seems did not work and had a new problem:
Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.

I do not understand why! thanks!

YES. This error is caused by mixing up the username and the database user.
The Admin USERname (on top) is put in the field for the database-user.
The system is generating a password for the databaseuser, one that is not input.
So Nextcloud has no access to the database with these wrong credentials.

This is on a fresh install of

This is not good!

And this issue is NOT SOLVED in !!

Now we get ‘405 Not Allowed’ after the initial setup …
And the database credentials in the config are wrong.

But the database is created …
So changing the databaseuser and password in the config.php to the correct ones …
results in ‘Internal Server Error

So, perhaps I should try to install with same names and passwords for database user and admin user …

And that does not work either.
The system puts oc_ in front of the database username and that is wrong.
And it keeps generating a password that is not the input in any field.

I have exactly the same behavior in NC 17 and 16.
So this may be an issue with NGINX, PHP 7.2 or 7.3 or MariaDB10 …

Same error with renaming daatabase user and password with Apache 2.4.

Hello everybody. I know this post has been inactive for more than two years, but I’m still getting this error while trying to configure Nextcloud 18 on Ubuntu 20.04.

I took a look also at this discussion, but it hasn’t been of much help, unfortunately.

I Have the latest versions of MySQL, Apache and php.

I went through the steps @berniejo suggested, but nextcloud won’t allow me to use the same user I previously configured, it adds an index at the end to create a new user. In my case, if I tried another time, I’d get: 'oc_xplosionmind1'

Please help me, I’m getting crazy!

NOTE: not using Docker or Docker compose as @akrea

Here’s a screenshot:

@xplosionmind did you find a solution ? I have the same error and tried most of what is mentioned in this tread but nothing worked. I’m on Synology with MariaDB10 but it looks like the same problem happens whatever the server type is.

1 Like

Hi! Actually, I don’t remember, but I think i did, since I’m using Nextcloud right now. I wrote a step-by-step guide and procedure you can find here. If I remember correctly, it was a database issue.

I hope my walktrough can be useful to you.


It was a MariaDB 5 vs 10 problem. localhost was pointing to MariaDB5 on port 3306 but even if I force to localhost:3307 it was looking in MariaDB5. The solution was to use, no idea why it makes any difference between localhost and but it works now!

1 Like