Error creating admin user

#1

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!

#2

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'@'10.252.174.9' identified by 'apasswordyoupickhere';
> flush privileges;
> exit;

10.252.174.9 could by localhost if MariaDB is on the same server.

#3

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

#4

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.

#5

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 https://askubuntu.com/questions/763336/cannot-enter-phpmyadmin-as-root-mysql-5-7.

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!

#6

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?

#7

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?

#8

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
#9

OK, I found the real answer for this. See the post at the bottom of this page:
https://dev.mysql.com/doc/refman/5.7/en/default-privileges.html

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:
https://docs.nextcloud.com/server/16/admin_manual/installation/source_installation.html#example-installation-on-ubuntu-18-04-lts-server

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:

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

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.