MongoDB import, export, backup, recovery, user authorization (4), mongodb Import

Source: Internet
Author: User
Tags mongodump mongorestore

MongoDB import, export, backup, recovery, user authorization (4), mongodb Import
V. MongoDB import, export, backup, recovery, and user authorization

I. Data export and Data Import
As a DBA (Administrator), you often need to import and export data. The following describes the utility (included ):
1: Data Import Export
Export csv files
./Export-d Test-c user1-o/tmp/user1.out -- specify the location and file name of the exported file
Database set (table)
./Export-d my_mongodbTest-c user -- csv-f uid, name, age-o user_csv.dat
Parameter description:
-D is the database
-C is a set
-O output file name
-Csv indicates that the file to be exported is in csv format.
-F indicates the columns (fields) to be exported)
For more details, refer to export-h.

2. import data to external Import
./Export Import-d test-c user1/tmp/user1.out -- import the/tmp/user1.out file to the user1 collection of the test database.

Ii. Data Backup and data recovery-the backup file is a pile of bson files
As a DBA (Administrator), it is very important to back up the data required for importing and exporting data. The following describes the utility (provided by Alibaba Cloud ):
1: Data Backup mongodump (a large collection contains a bson file)
./Mongodump-d test-o/tmp/-- back up the test database to/tmp/, and A/tmp/test/xxx. bson... file will be generated.
-D database
-H: view detailed parameters
* If no directory is specified, a dump directory is created under the current file directory (bin) by default to store the backed up files.
You can specify the directory by yourself: Add-o/tmp/my_mongodb_dump to the directory to which the backup is backed up.

2: Data Recovery mongorestore
./Mongorestore-d test/tmp/test -- Restore/tmp/test data to the test database.

Iii. User security and authentication (user authorization)
Mongodb administrator: Super administrator, administrator of each database
The databases in each mongodb instance have many users. After security authentication is enabled, only database authenticated users can perform read/write operations,
By default, mongodb does not verify the user name and password. After mongodb is started, you can directly use the mongo link to use it and have the root permission for all data.
Therefore, you can specify parameters at startup to prevent client access and links.
You only need to specify the -- auth parameter at startup.
 
Detailed operation steps: (the super administrator is used by default when the first request comes in, and permissions can be set when the -- auth is added during login)

1->./mongod -- auth -- dbpath =/usr/local/mongodb/data/-- logpath =/usr/local/mongodb/dblogs -- fork start mongodb
1-> show dbs
2-> use admin -- go to mongodb and show dbs to view the admin database.
3-> db. addUser ("root", "123456"); Press enter to create a super administrator. Press enter to have a value readOnly: false to indicate readable and writable.
4-> exit -- set it and you will find that everything is useless. log out and log on again.
5->./mongo-h -- check the parameter-u-p.
6->./mongo localhost: 27017/test anonymous user logs on to the test database, you will find that the operation is not allowed
7->./mongo-uroot-p123456 localhost: 27017/test -- you will find that this is not the case. Here the test entry is required to go to the admin database for verification.
-- Because the root user we just added is added to the admin database, the admin database and the super user of the whole site. We need to verify the login under admin.
8->./mongo-uroot-p123456 localhost: 27017/admin -- that's all.

Add a user to test (the same applies to other databases used for creation)
* Note: The user added to the test can only have operation permissions on the test data, but cannot operate other databases. The super administrator in the admin can
Use test
Db. addUser ("user1", "123456 ");
./Mongo-uuser1-p123456 localhost: 27017/test -- to verify

After setting: The next time you use mongodb, You have:
1: Start mongodb
./Mongod -- auth -- dbpath =/usr/local/mongodb/data/-- logpath =/usr/local/mongodb/dblogs -- fork
2: User Logon:
./Mongo-uroot-p123456 localhost: 27017/admin

Who has an apsaradb for mongodb advanced video tutorial?

Are you learning this software?

After Apple 4 is restored, use the pp assistant to restore its backup. The Restoration fails and the solution is ...... The following is a recovery failure prompt ......

Pp assistant failed to load backup. You can use backup on itunes or backup on icloud drive.
Connect to itunes and select the option not to select the new iPhone to fill the iphone with backup
In the restored boot screen of the new machine, select language service or something, log on to your Apple account, log on, and choose "icloud backup" to load the iPhone.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.