Error creating admin user

I’ve been trying to install without much success.

I’m on the graphical wizard and failing on database connect / admin user.

I’ve entered the correct details, but it keeps failing with

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 'oc_kachada'@'localhost' to database 'nextcloud'

I’ve created the database and tried without db. The database admin user has rights to create tables and users, and I can see an oc_kachada user created.

I tried granting all privs on the . to the newly created user but when I run the install again it creates a new user, oc_kachada1.

This is a fresh server install, and for what it’s worth MariaDB seems to have taken over MySql, I haven’t seen or used that before but from what I can tell root user has gone, at least for non-sudo. I had to create a new user which I can log in with and create tables, users, grant perms etc. This is the user I’m entering as the database user. I can also login and do admin using phpMyAdmin with this user.

MariaDB version is 10.1.23-MariaDB-9+deb9u1.

I’m kinda stuck at this point, not really sure where to look next or what to do so any direction appreciated!

MariaDB uses socket rather than user/password by default IIRC.

It seems to me like you’re putting in the root user and password during the wizard. As a work-around you could setup the user manually in MariaDB and ensure the IP it’s connecting from is permitted. Something like:

> sudo mysql
> create database yournewdb;
> grant all privileges on yournewdb.* to 'anewuser'@'' identified by 'apasswordyoupickhere';
> flush privileges;
> exit; could by localhost if MariaDB is on the same server.

Thanks for the suggestion. I’ve actually been removing and reinstalling mysql trying to get rid of MariaDB but the two seem to be joined at the hips.

I created the new db and user as given in your example, everything is installed on the same machine. When I tried the installer again it came up with the same error and created user oc_kachada1. I granted permissions to that user, flushed and retried and it created oc_kachada2. It wants to create a new user and connect with that. Is there a permission I’m missing from my mysql admin account maybe? How to check this and compare with root?

Life was so much simpler when we could just use root for everything :rofl:

If it makes any difference I’m on Debian Stretch

When you’ve created the user via CLI, you input that user and password in the Wizard, along with the DB name and “localhost” right?

I don’t see how it will be making other accounts.

That is correct, I also tried localhost:port

I think I have now fixed it, with the help from your first response and the accepted answer at

The key part was to add “WITH GRANT OPTION” to my database admin account. Without that I guess it could not grant permissions to the tables of the newly created users. I also guess that when the process starts again, it sees the username has already been taken, so created the next available in the sequence.

Thanks for your help, you pointed me in the right direction!

So mysqladmin is basically broken by this unix_socket login, which is also default on MariaDB since longer time? Can’t mysqladmin just use the mysql root user with (or without, doesn’t matter) password as unix root user?

Hi all, I’ve got the same problem. I’m just reinstalling Ubuntu because I couldn’t find a solution.

I notice this topic is a year old. Is there any smoother way of getting round it, before I start the Nextcloud installation process. On the Nextcloud manual, it still says:

At the installation of the MySQL/MariaDB server, you will be prompted to create a root password. Be sure to remember your password as you will need it during Nextcloud database setup.

Shouldn’t this be updated to reflect the problems?

I just hit this as well in my first attempt to install nextcloud, using occ on a VPS running ubuntu 18.04, following the most vanilla instructions. It’s unfortunate to have my first encounter with nextcloud include:

  • the documentation is wrong, as it never prompts for a password
  • fails with an error meaningless to a non-database-admin, the workarounds discussed here presuppose prior facility with a great deal of irrelevant mysql/mariadb arcana
  • and the issue was identified in 2017 and bumped in november 2018
1 Like

OK, I found the real answer for this. See the post at the bottom of this page:

The short version - you do not set or need to set a password for the mysql/mariaDB root user on Ubuntu anymore. You must run mysql as root to use the root account, but that alone is sufficient. This can apparently be changed but on a single server, it’s secure as long as your server root is.

Assuming you’re following this documentation:

Here’s the where this comes into play:

After installing all the pre-reqs, log into mysql/mariadb and create the Nextcloud user account and database. This is the account that Nextcloud will use to access the database, and this account has nothing to do with any “actual” Nextcloud users.

sudo mysql -u root --skip-password
CREATE USER ‘nc_user’@‘localhost’ IDENTIFIED BY ‘strongpasswordhere’;

This user/pass is what you will plug into Nextcloud setup later on. Make sure you’re using a strong password.
Now create the database, and give our NC user rights on it:

GRANT ALL PRIVILEGES on nextcloud.* to ‘nc_user’@‘localhost’ IDENTIFIED BY ‘samestrongpassword’;
flush privileges;

At this point you should probably never need to mess with the DB again outside of backups, or if you want to enable utf8mb4, or add any apps that need their own database, etc.

Finish remaining setup steps until you’ve got the setup wizard up.

Enter a nextcloud admin username and password to create.

Data folder: There are valid reasons to move this from the default location. If you are interested in doing so, it’s outside the scope of this little walkthrough, but I strongly suggest you stop and research, and make that decision now. Changing it later requires modifying the database contents.

db user: nc_user (the user we created above - NOT ROOT)
password: the strong password you set for nc_user
db name: nextcloud
db host: localhost

When you hit Finish Setup, everything should work. I strongly recommend looking through the documentation and performing post-install optional configuration and hardening steps.

CREATE USER ‘nc_user’@‘localhost’ IDENTIFIED BY ‘…’;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘‘…’ at line 1

It is really a shame that I have to sit for hours trying to install nextcloud, what should take me 30 minutes. Why is the documention so bad?

Hi, I also have this problem and cannot find a solution. Pity.

Hello !

I have an OVH VPS and i had the same problem.

To fix it, I have purge all package mariadb and mysql one by one :
sudo systemctl stop mariadb to stop database
sudo pkill mysql to kill mysql service that I couldn’t stop
sudo pkill mysqld_safe same for mysql daemon
sudo pkill mysqld_safe same for this daemon
sudo dpkg -l | grep mariadb to find mariadb package to drop
sudo dpkg -l | grep mysql to find mysql package
sudo apt-get purge <package_name> <package_name2> ... to delete the selected packages
sudo apt update to be sure to have the last version
sudo apt install mariadb-server to reinstall mariadb
sudo apt install mysql-common to reinstall mysql common
sudo systemctl start mariadb to start mariadb service
sudo mysql -u root
MariaDB > create database <my_db> to create the nextcloud database
MariaDB > grant all privileges on <my_db>.* to '<my_db_user>'@'localhost' identified by '<my_secure_pwd>'; to add a new user with privileges
MariaDB > flush privileges; to flush privileges

If you have a problem with your mariadb localhost user, check /etc/hosts. You must have in first line : localhost

If you have connection problem, you can check your db port in mariadb :

After that, I made the following command in nextcloud folder :
sudo -u www-data php occ maintenance:install --database "mysql" --database-name "<my_db>" --database-user "<my_db_user>" --admin-user "<my_new_cloudnext_user>" --database-port <my_db_port>

And it’s OK : Nextcloud was successfully installed

Probably some actions are useless, but on my VPS, it’s worked.

I wish that it could be help you.


Merci Guillaume!! That helped me a lot.
I followed all these steps. The last command failed - “Could not open input file: occ” - but then I went back to the Nextcloud ‘create admin’ screen, added the MariaDB port (3306 for me) after localhost, and was able to finally create my new user. Phew… :sweat_smile:

Still happening today. Guillaume’s helped.
A better solution than “reinstall the whole thing” would be appreciated :slight_smile:

This is one of those see the grass for the tress" problems. The instruction I used had this:

CREATE USER 'nextcloud_admin'@'localhost' IDENTIFIED BY 'your-password-here';
GRANT ALL ON nextcloud.* TO 'nextcloud_admin'@'localhost';
After looking around the net, I found the newer version of MySql needs more to grant access. 

GRANT ALL ON nextcloud.* TO 'nextcloud_admin'@'localhost' IDENTIFIED BY 'your-password-here';

I hope someone finds this helpful. 

The orignal install instructions I was following came from this site:

This is the site that helped me figure out what was causing the error :
1 Like

Merci Guillaume, I can go to sleep now :slight_smile:

This worked for me. Thanks!

I have had the same issue from nextcloud installation while trying to connect to the database I was given the error "nextcloud: Error while trying to create admin user: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [1045] Access denied for user ‘greg’@‘localhost’ (using password: YES)

Solution for me was very simple, I had tried everything and what worked was something alot of posts are not telling.

SOLUTION: there is a conflict with your folder permissions and also your username for the new NEXTCLOUD account. Try my easy solutionif you are having difficulty to connect to the database because it may not be anything related to the database or nextcloud at all.

steps1: Go to settings and select “new permissions” select all drives and all shares and press start. Then go back to the NEXTCLOUD setup page and change your new admin username to something a bit different, dont use admin or short 4 letter names. for me I changed mine from greg to greg 1234 and then I was able to connect and I was brought to the nextcloud welcome screen finally. Who would think that just something as simple as an incompatible name for admin user would prevent connection to the database. The name you create doesnt have to match any other name of user, just make a different name than the one you have because if nextcloud doesnt like that particular name it won’t connect. Don’t use admin-other, I tried anything with admin wont succeed. My name and 1234 worked like a charm. But this is just my situation, I couldnt find anything else wrong with it.
another good place to start is to not use the defualt installation to setup your database name and user This is bad and it won’t work there are bugs in so much of this shitty software, especially mariadb and mysql its all garbage whoever programs it doesnt know what they are doing. To setup a database always use the comand line or it won’t work OK we have established that now I’ll show you how. First go here and read the entire page specifically the parts where it tells you the commands to type for a new database.

This really helped me out. Also use “/Data” for your nextcloud directory on the initial login screen dont change it. Don’t use “/config/www/nextcloud/data”

These are the only commands you should be using and use a notepad to save your choices as a reference so u can copy and paste and don’t fudge it up because it gets confusing with so many names and passwords.

mysql -uroot -p
CREATE USER ‘username’@‘your ip address of server’ IDENTIFIED BY ‘password’;
FLUSH privileges;

Wow this is like magic, copy and paste this into a notepad and fill in your desired password and username and bingo you will succeed, don’t give up even if nextcloud is a shitt y software it is needed sometimes to have cloud and this is all there is besides seafile which is even crummier. Remember, just change your admin name to something longer this is not an issue with the database at all nextcloud just doesn’t like the name you chose for the new admin account. I don’t like nextcloud for giving me this hassle, I hope everything works out for you guys trying to get this resolved and my stupid solution works for lots of people.

These are not apostrophes (U+0027) in your comment but Left Single Quotation Marks (U+2018). The former encloses a string literal but the latter is just a regular character. I copied the code you have quoted and ended up with a database user called “‘nc_user‘” (the quotation marks are part of the name). Took me a while to figure out what had happened.
To anyone wishing to copy this code: be careful, delete the example values together with the quotation marks and then put in your values.