Solution to error 1045 in mysqldump

Error message:
mysqldump: Got error: 1045: Access denied for user ‘root’@’localhost’ (using pas
sword: YES) when trying to connect
Operating environment: CMD
You can log into mysql normally with root-@localhost, but mySQldump denied access, checked the root permission, found that there was no problem with the permission, and finally decided to create a new experiment account

CREATE USER dumper@'localhost' IDENTIFIED BY 'dumper';
GRANT select ON test.* TO dumper@localhost;
GRANT show view ON test.* TO dumper@localhost;
GRANT trigger ON test.* TO dumper@localhost;
GRANT lock tables ON test.* TO dumper@localhost;

Dumper is set to back up the Test library, can log in to the database normally, and still cannot access mySQldump
I began to add parameters to mySQldump gradually, and finally found that the access was successful after adding port -P3307

mysqldump -udumper -pdumper -hlocalhost -P3307 test>test.sql

According to the configuration file, the port of mysql has been modified to 3307, but mySQldump defaults to 3306. After that, the root account can also be normally backed up

Read More: