Error while trying to create admin user: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [1044] Access denied for user 'newuser'@'localhost' to database 'new-database'

So I have been using NC since they split form OC. Was using OC for several years before that. Today I set about moving from an old server to a new box. Old machine was running Ubuntu 16.04 and the new box 18.04.

I downloaded NC15 and NC14 and attempted to install each one as a test site and attempted to go through the installation setup. I get the following error

Error while trying to create admin user: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [1044] Access denied for user ‘newuser’@‘localhost’ to database ‘new-database’

I have created a new user and given it full permissions because I see that the root user may have problems. This made no difference.

I have attempted to create the database first and not create the database first. No difference.

I have attempted to use 127.0.0.1:3306 in place of localhost no difference.

I am stumped as to how to get this to work. In an effort to test my server I downloaded wordpress and had it installed and operating in about 2 minutes. So the server is working fine. Could there be something missing setup wise. I am not seeing much in the log files during this either.

Thanks for any help you can provide.

OK, so some additional information. I tried installing again but this time I made sure the user that nextcloud would create was not already a user. Then I set the non existent user to have permission to the database I was pointing the install towards. This worked. So there is a problem giving the new user the proper permissions. The problem with the install is when you try to manually assist by fixing permissions and rerun the install it generates a user1, user2, user3 so you have to be ahead of the installer.

I hope this give someone an idea of how to help me fix this issue.

Kent

I’m having the same issue, it’s driving me crazy. I’m trying to get Nextcloud going in a docker container, but every time I try to get the initial startup, it does not use my environmental attributes and creates a numbered version of my admin account I’m trying tot create.

I’m up to admin_33 now.

I changed my original question as I figure out today that my transferred installations from my old server were having a redis memcache issue. I removed that from the config file and the sites lit right up. Now I have to figure out that issue. The error when attempting to install is still there. I have a work around but it’s a pain.

I can answer this for people. The username and database password in the config file are just as they are in the database. So the password is not salted. I was able to create the user with the listed password in the new database and it works. I ran across some discussion on this matter while trying to get my sites working.

In case anyone else encounters this too (i got it after migrating to a new system by restoring database backup):

This (…) occurs because the database user created for Nextcloud has permission to create new users, but is not allowed to grant permissions.

Log in to mysql with

sudo mysql --user=root mysql

Then run

grant all privileges on *.* to 'database username'@'localhost' with grant option;

Exit with CTRL+D

1 Like

Dude, saved me. Thank you so much.