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

10.252.174.9 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 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!

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:
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.

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 :
127.0.0.1 localhost

If you have connection problem, you can check your db port in mariadb :
MariaDB > SHOW GLOBAL VARIABLES LIKE 'PORT';

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.

Guillaume.

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 DATABASE nextcloud;
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:
 https://www.samueldowling.com/2020/07/24/install-nextcloud-on-freenas-iocage-jail-with-hardened-security/

This is the site that helped me figure out what was causing the error : 
https://www.linuxbabe.com/ubuntu/install-nextcloud-ubuntu-18-04-nginx-lemp
1 Like

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

This worked for me. Thanks!

SUPER SIMPLE SOLUTION
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.

https://docs.nextcloud.com/server/14/admin_manual/configuration_database/linux_database_configuration.html

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
password
CREATE USER ā€˜usernameā€™@ā€˜your ip address of serverā€™ IDENTIFIED BY ā€˜passwordā€™;
CREATE DATABASE IF NOT EXISTS ;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON .* TO ā€˜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.