1

cmd init

cmd := exec.Command("mysqldump",
        "--column-statistics=0",
        "--default-character-set=utf8",
        "-P", port,
        "-h", host,
        "-u", username,
        fmt.Sprintf("-p'%s'", password),
        dbname)

error text i get

mysqldump: [Warning] Using a password on the command line interface can be insecure. mysqldump: Got error: 1045: Access denied for user 'user'@'ipaddress' (using password: YES) when trying to connect

cmd.String() output

/usr/bin/mysqldump --column-statistics=0 --default-character-set=utf8 -P port -h host -u username -p'password' dbname

when I execute cmd.String() output in terminal on same machine, everything works as expected. What reasons can be for this behavior?

Sergey
  • 421
  • 1
  • 5
  • 14

1 Answers1

0

You probably have an anonymous user ''@'localhost' or ''@'127.0.0.1'.

run mysql> SELECT user, host FROM mysql.user; to see what users you have on mySQL.

Documentation:

When multiple matches are possible, the server must determine which of them to use. It resolves this issue as follows: (...)

When a client attempts to connect, the server looks through the rows [of table mysql.user] in sorted order. The server uses the first row that matches the client host name and user name. (...) The server uses sorting rules that order rows with the most-specific Host values first. Literal host names [such as 'localhost'] and IP addresses are the most specific.

Note: an empty string acts a wildcard in MySQL's authentication algorithm

ied3vil
  • 964
  • 1
  • 7
  • 18
  • You should though lookup for others who have this problem before posting the question, just saying... – ied3vil Nov 27 '19 at 15:10
  • There is anonymous user, but I connect to database not on localhost. Host in entry for my user in user table looks like 1.1.%. And ip of the server, from which I am connecting, looks like 1.1.2.3. So there should be a match – Sergey Nov 27 '19 at 15:52