Directus could not connect to mariadb

during deployment of Directus - we encounter this error:

i checked the env with the correct details

Hello @Karlomac01,

First of all, welcome to the Cleavr forum.

I checked your settings and they all look fine to me.

I wonder from the error if you also need to add DB_CHARSET. Try adding that to the env and see if that resolves the issue.

Hi

Its strange the error says that root@localhost is trying to access the database. I connected to the database and no entry for root@localhost. Perhaps during creation of the database, this was not added?

also it seems the .env config is not being read because it clearly has a defined db_ database, user, password in there. Perhaps initial connection needs root@ access before the .env ?

Your thoughts would be much appreciated.

Sincerely,

Karlo M.

Hello @Karlomac01,

We’ll look into the issue and get back to you.

Hello @Karlomac01,

I tried reproducing the issue and also used a different set of database usernames/passwords.

But the deployment was successful.

I’m still looking at this but can you make sure that you can access the database by using a database client such as TablePlus or by SSHing into your server? So that I could dig into the cause of this issue.

as you can see, using tableplus i was able to connect to the database using cleavr account and via ssh. I also used the registered user in cleavr for the database i am connecting to.

also - connecting to the database shows that directus has not initialized the database as yet.

Perhaps it’s an issue with creating the database - not initialising properly? Maybe i made a mistake in the process?

Hello @Karlomac01,

As far as I understood the issue is related to the database users. Can you please confirm the database name and user used in your webapp’s environment are the same by going to Webapp < Environment?

Also, I would like to recommend you to follow our docs once for the Directus deployment from here How to deploy Directus using Cleavr - Cleavr docs if you haven’t already.

I hope this helps.

Do let us know if the issue persists even after this.

Hi Anish,

thank you for your comment and suggestion.

Yes it does have the correct environment settings , however, as you can see in the error i posted, it seems its trying to access the database using “root@localhost”

As far as i know, at this stage, the root@localhost should have been added at the time the database was created or cleavr is not reading the env during directus deploy

regards,

Karlo M

Hello @Karlomac01,

Ah! Looks like the build step is requiring the .env file. I missed to notice that before. Can you try creating a custom hook with the script exactly like in the link: quick-scripts/link-.env.md at master · cleavr/quick-scripts · GitHub and see if that works?

Make sure to put the hook right before the build step and try re-deploying.

Please let us know whether this works or not.

Do you have your .env file pushed to your repo by any chance? If so, you need to delete that first - it isn’t a good security practice as well as that is going to create a conflict as it will override the one uploaded through Cleavr.

Hi - thank you for your reply.

Nope, i never push my .env file into repos.

Any other ideas? I tried doing this again using the tutorial on your docs but had the same error. The only difference was i used my own domain.

I appreciate your help.

Hi Anish,

this process did not work.

did i do this correctly?

Hey @Karlomac01 -

I’ll send you a direct message, I’ve got a pretty good idea of what the issue might be. :slight_smile:

My bad! thank you for your help!

I works perfectly now!

regards,

Karlo M.

1 Like