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.