Create users, tablespace, import and export in Oracle

Source: Internet
Author: User

// Create temporary tablespace test_temp

Tempfile 'e: \ oracle \ product \ 10.2.0 \ oradata \ testserver \ test_temp01.dbf'

Size 32 m

Autoextend on

Next 32 m

Maxsize 2048 m

Extent management local;

// Create a data table space

Create tablespace test_data

Logging

Datafile 'e: \ oracle \ product \ 10.2.0 \ oradata \ testserver \ test_data01.dbf'

Size 32 m

Autoextend on

Next 32 m

Maxsize 2048 m

Extent management local;

// Create a user and specify the tablespace

Create user testserver_user identified by testserver_user default tablespace test_data temporary tablespace test_temp;

// Grant permissions to users

Grant connect, resource to testserver_user; (DB2: Specify all permissions)

// Delete a user

Drop user testserver_user cascade;

Import and Export commands: Oracle Data Import and Export imp/exp is equivalent to Oracle data restoration and backup. The exp command can export data from the remote database server to the local DMP file, and the IMP command can import the DMP file from the local to the distant database server. This function can be used to build two identical databases, one for testing and the other for formal use.

Execution Environment: In sqlplus. execute in EXE or DoS (command line). When dos can be executed, because the installation directory ora81bin in Oracle 8i is set to a global path, there is exp in this directory. EXE and imp. the EXE file is used for import and export. Oracle is written in Java. sqlplus. EXE, exp. EXE, and imp. EXE files may be packaged class files. Sqlplus. EXE calls the classes encapsulated by exp. EXE and imp. EXE to complete the Import and Export function.

The following describes the Import and Export instances.

Data export:

1. Export the database test completely, and the username System Password Manager is exported to D: daochu. dmp.

Exp system/manager @ test file = D: daochu. dmp full = y

2. Export the tables of system users and SYS users in the database

Exp system/manager @ test file = D: daochu. dmp owner = (system, sys)

During exp export, If you export data based on the user, all the table structures and objects under the user will be exported, and unwanted tables cannot be filtered out, therefore, you do not need to import the backup table to the test database. The statement for exporting the table should be:

Exp JX/JX @ JX owner = JX rows = n file = D: \ jx. dmp statistics = none direct = y

3. Export the inner_policy and policy_staff_relat tables in the database.

Exp aichannel/aichannel @ testdb2 file = D: datanewsmgnt. dmp tables = (inner_policy, policy_staff_relat)

4. Export the data with the field filed1 in table 1 in the database starting with "00"

Exp system/manager @ test file = D: daochu. dmp tables = (Table1) query = "where filed1 like '201312 '"

The above is a commonly used export. For compression, you can use WinZip to compress the DMP file. You can also add compress = Y to the command above.

Import data 1 import the data in D: daochu. dmp to the test database.

IMP system/manager @ test file = D: daochu. dmp

IMP aichannel/aichannel @ HUST full = y file = D: datanewsmgnt. dmp ignore = y

The above may be a problem, because some tables already exist, and then it will report an error, the table will not be imported. Add ignore = Y to the end.

IMP jx_test/jx_test @ jxkf fromuser = JX touser = jx_test file = D: \ jx. dmp statistics = none ignore = y

2. Import table 1 in D: daochu. dmp to IMP system/manager @ test file = D: daochu. dmp tables = (Table1)

The preceding import and export operations are sufficient. In many cases, you must first completely delete the table and then import it.

 

Note: If the operator has sufficient permissions, a prompt is displayed.

Databases can be connected. You can use tnsping test to obtain whether the database test can be connected.

Appendix 1: add data import permissions to users. First, start SQL * puls.

Second, log in with system/Manager

Third, create user username identified by password (this step can be omitted if you have already created a user)

Fourth, grant create user, drop user, alter user, create any view, drop any view, exp_full_database, imp_full_database, DBA, connect, resource, create session to Username

Fifth, run-cmd-to enter the directory where the DMP file is located. IMP userid = system/manager full = y file = *. DMP or imp userid = system/manager full = y file = filename. DMP execution example: F: workoracle_databackup> imp userid = test/test full = y file = inner_policy.dmp

Display: Import: Release 8.1.7.0.0-production on Thursday February 16 16:50:05 2006

(C) Copyright 2000 Oracle Corporation. All rights reserved.

Connect to: Oracle8i Enterprise Edition Release 8.1.7.0.0-Production

With the partitioning option jserver release 8.1.7.0.0-Production

Export the files created by export: v08.01.07 in the normal path

The zhs16gbk Character Set and zhs16gbk nchar character set have been imported.

The export server uses the utf8 nchar character set (possible ncharset conversion)

. Importing aichannel object to aichannel... importing table...

"Inner_policy"

Four rows are imported to prepare to enable constraints... the import is terminated successfully, but a warning is displayed.

Appendix 2: Oracle does not allow you to directly change the table owner. You can use export/import to achieve this purpose. Create import9.par first, and then run the following command during use:

IMP parfile =/filepath/import9.par

The content of import9.par is as follows:

Fromuser = tgpms

Touser = tgpms2 (Note: You can change the table owner from fromuser to touser. Users of fromuser and touser can be different)

Rows = y

Indexes = y

Grants = y

Constraints = y

Buffer= 409600

File =/backup/ctgpc_20030623.dmp

Log =/backup/import_20030623.log

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.