by Ken Task.
The DB information in your config.php ... user, password, host, etc. provides information for you concerning how to use mysqldump from CLI on the server where the Moodle code resides.
If the DB server is localhost means the DB server IS on the same server as the code, that should mean one could use mysqldump *minus* the host option/switch in command.
As an example:
In config.php DB server is localhost, DB user=mdbadmin, DB=moodle, DB Password="SomeSecureTypePassword".
From CLI of the server where the code and DB server resides.
mysqldump -u [dbuserfromconfig] -p[dbpasswordfromconfig] [databasename] > /path/to/[databasename].sql
There is *NO SPACE* between the -p option and the [dbpasswordfromconfig] *AND* if it contains any characters that might be mis-interpreted from the shell using, enclose the password in 'ticks'.
-p'[dbpasswordfromconfig]'
Make sure the 'direction' is always > and NOT <. > = export ... < = import
There is also a catch 22 ... the DB user in config.php may not have privileges (permissions as they are called in MySQL-ese) to do it all. Might have to use the 'superuser' of the DB server in your command.
Your errors, however, indicate a syntax issue or the user in config.php is not the user you are using in your command.
Generally, when one sees/reads docs/blogs, etc.. things like DB names, logins, passwords shoud be considered 'placeholders' AND shouldn't be used verbatim.
Hope that helps!
'spirit of sharing', Ken