docker run --name mongodb4.4.6 --restart=on-failure -e MONGODB_ROOT_PASSWORD=Aa111111 -v /data/mongodb:/bitnami/mongodb -p 27017:27017 -d bitnami/mongodb:4.4.6
CREATE DATABASE user DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
/bitnami/mongodb/bak/zadig/zadig
mongorestore -uadmin -pAa111111 -d zadig --drop /bitnami/mongodb/bak/zadig/zadig --authenticationDatabase admin
mongorestore -uadmin -pAa111111 -d zadig_policy --drop /bitnami/mongodb/bak/zadig_policy/zadig_policy --authenticationDatabase admin
mongorestore -h 127.0.0.1 -u zadig -p zadig2020 --port 27017 -d zadig_policy --drop /bitnami/mongodb/bak/zadig_policy/zadig_policy
mongorestore -uzadig -pzadig2020 -d zadig --drop /bitnami/mongodb/bak/zadig/zadig --authenticationDatabase zadig
mongo --host 127.0.0.1 --port 27017 -u root -p Aa111111
-u 用户名 -p 密码
docker启动mongo
docker run --name mongodb4.4.6 --restart=on-failure -v \
/data/mongodb:/bitnami/mongodb -e MONGODB_USERNAME=zadig \
-e MONGODB_PASSWORD=zadig2022 -e MONGODB_DATABASE=zadig \
-p 27017:27017 -d bitnami/mongodb:4.4.6
登陆mongodb
mongo -uroot -pAa111111 127.0.0.1:27017/admin
创建用户
db.createUser({ user:'admin',pwd:'Aa111111',roles:[ { role:'userAdminAnyDatabase', db: 'admin'}]});
赋权
db.grantRolesToUser("zadig", [{ role: "dbOwner", db: "zadig_policy" }])
db.grantRolesToUser("zadig", [{ role: "dbAdmin", db: "zadig_policy" }])
db.grantRolesToUser("zadig", [{ role: "restore", db: "zadig_policy" }])
db.grantRolesToUser("zadig", [{ role: "restore", db: "zadig" }])
db.grantRolesToUser("admin", [{ role: "dbAdmin", db: "zadig" }])
db.grantRolesToUser("admin", [{ role: "dbOwner", db: "zadig" }])
db.grantRolesToUser("admin", [{ role: "dbAdmin", db: "zadig_policy" }])
db.grantRolesToUser("admin", [{ role: "dbOwner", db: "zadig_policy" }])
CREATE DATABASE user DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE DATABASE dex DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_general_ci;
Create user 'zadig'@'%' identified by 'zadig@2022';
grant all privileges on user.* to 'zadig'@'%';
grant all privileges on dex.* to 'zadig'@'%' ;
grant all PRIVILEGES on pay.* to pay@'%' identified by 'pay2022' ;
db.createUser({ user:'zadig',pwd:'zadig2022',roles:[ { role:'dbOwer', db: 'admin'}]});
db.grantRolesToUser("zadig", [{ role: "dbOwner", db: "zadig_policy" }])
db.grantRolesToUser("zadig", [{ role: "dbAdmin", db: "zadig_policy" }])
db.grantRolesToUser("zadig", [{ role: "restore", db: "zadig_policy" }])
db.grantRolesToUser("zadig", [{ role: "restore", db: "zadig" }])
db.grantRolesToUser("admin", [{ role: "dbAdmin", db: "zadig" }])
db.grantRolesToUser("admin", [{ role: "dbOwner", db: "zadig" }])
db.grantRolesToUser("admin", [{ role: "dbAdmin", db: "zadig_policy" }])
db.grantRolesToUser("admin", [{ role: "dbOwner", db: "zadig_policy" }])