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]  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’;
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’;
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.