Can't initialize NextCloud. It won't connect to MySQL. Error: SQLSTATE[HY000] [2002] No such file or directory

Update: Still not working, but getting closer.

Using 127.0.0.1 as my DB host (instead of localhost) in the NC installation wizard seems to get me closer to a solution. This was discovered on this StackOverflow answer.

Additionally, I discovered I needed to append the correct port to the host address, e.g. 127.0.0.1:3306.

I created a nextcloud database in MySQL.

CREATE DATABASE nextcloud;

I then created a new DB user and granted the user access to the DB.

CREATE USER '<user>'@'127.0.0.1' IDENTIFIED BY '<password>';
GRANT ALL ON nextcloud.* TO '<user>'@'127.0.0.1';

Even after running the query, though, I get this error in the NC initialization wizard:

MySQL username and/or password not valid You need to enter details of an existing account.