解决Docker中备份mongodb不成功问题。报错原因:error occured during connection handshake: auth error: sasl conversatio
1.进入容器:
docker ps
docker exec -it 容器名/ID bash
备份mongodb命令:mongodump -h 172.19.19.41 --port 27017 -u='admin' -p='********' -d ******* -o ./backup/
出现报错:Failed: can't create session: could not connect to server: connection() error occured during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
解决方法:
添加参数:--authenticationDatabase admin
参数含义:
解释1.安全登录认证,mongodb本身的一种安全认证登录方式,参数就相当于指定admin数据库。
解释2.在连接mongo时,使用参数 --authenticationDatabase,会认证 -u 和 -p 参数指定的账户和密码。如果没有指定验证数据库,mongo使用连接字符串中指定的DB作为验证数据块。
修改后为:mongodump -h 172.19.19.41 --port 27017 --authenticationDatabase admin -u='admin' -p='*******' -d ******* -o ./backup/
ok!正常备份!