Hi Marta.
When you say you've entered database parameters for name, hostname, user, password, etc, are you being literal that those are the actual settings you are using? Or did you change those so as to not share them with everyone in the forum (good idea by the way). If you are literally using "mydatabasename", "www.mydomain.com", "myusername" then these are only example settings and I am doubtful that those settings represent your environment. Sorry if this is a dumb question :-)
My first step in troubleshooting "Failed to connect to database" errors would be to try to make a connection from outside of Totara, using something like the mysql command line client or another GUI type of database tool. The best way to test would be to do this from the web server where Totara is using. Here is an example using the mysql command line database client (if running server on unix/linux, this can be executed from a terminal or console application). It uses the parameters you posted above:
mysql --host=www.mydomain.com --user=myusername --password=mypassword
If that command is successful you will see a mysql prompt, such as:
mysql>
At which point you can type something like:
mysql> show databases;
Which should show your mydatabasename database.
If it fails, you might see something like "Access denied for myusername" or "unknown mysql server host www.mydomain.com"
These basic troubleshooting steps can help to verify if you have your database settings correct or not.
You would also want to verify that your database has a user defined that allows access to the database you need from the IP address of the Totara web server.
I hope these troubleshooting tips aren't too basic but perhaps it will get you going in the right direction.