Oracle creation, deletion, import, and export Command Line Summary

Source: Internet
Author: User

Note:

The password entered during database creation is to change the default password of the system, the password you need to enter when logging on with the system, sysman, and other system default identities is the modified password (the password entered when you create a database)

To create a new user, you must log on to the system or sysman (the two have the maximum permissions) before creating a new user.

Create user format: create user username identified by password (for example, create user cht identified by cht ;)

After creation, you must assign permissions. Otherwise, you cannot connect to the database or sqlplus.

Therefore, grant connect, resource, dba to cht; then the database can be connected through cht/cht. The select, update, delete, and insert permissions do not need to be assigned, because each user has these basic permissions by default.

How to connect to a database using the command line method:

Start = run = cmd

Method 1:

Enter sqlplus and press Enter.

Enter the User name: system, and press Enter.

Enter the password orcl and press Enter.

Method 2:

Enter sqlplus system/orcl @ orcl, and press enter (system is the username, orcl is the password, and @ is the library name)

(After the database is installed, there are two system-level users:

1) the default system password is manager.

2) sys default password: change_on_install)

You must create a temporary tablespace and a data table space before creating a user. Otherwise, the default system tablespace is not good.

// Create a temporary tablespace

Create temporary tablespace zfmi_temp tempfile 'd: oracleoradatazfmizfmi_temp.dbf 'size 100 m autoextend on next 32 m maxsize 2048 m extent management local;

Note:

1. Name of zfmi_temp tablespace

2. D: the place where oracleoradatazfmi stores database files. Generally, it is the folder of control files, data files and log files after the database is installed, plus the name of the tablespace to be created + dbf (data file)

3. initial size of the 100 M tablespace

4. The size of 32 MB tablespace automatically increases

5. Maximum tablespace size of 2048 MB

// Create a data table space

Create tablespace zfmi logging datafile 'd: oracleoradatazfmizfmi. dbf'size 100 m autoextend on next 32 m maxsize 2048 m extent management local;

// Create a user and specify the tablespace

Create user zfmi identified by zfmi default tablespace zfmi temporary tablespace zfmi_temp;

// Grant permissions to users

Grant connect, resource dba to zfmi; (dba: Specify all permissions)

This step completes the creation of a user.

//////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// ////////////////////////////////////////

// Delete the user and all objects of the user

Drop user zfmi cascade;

// The cascade parameter is used to cascade the deletion of all objects of the user. if the user has an object but does not add this parameter, the user cannot delete it. Therefore, this parameter is habitually added.

// Delete the tablespace

Prerequisites: before deleting a tablespace, make sure that the tablespace is not used by other users before deleting it.

Drop tablespace zfmi including contents and datafiles cascade onstraints;

// Including contents deletes the content in the tablespace. If the content in the tablespace is not added before the tablespace is deleted, the tablespace cannot be deleted. Therefore, this parameter is habitually added.

// Including datafiles Delete the data files in the tablespace

// Cascade constraints

If the tablespace file is deleted before the tablespace is deleted, the solution is as follows:

If the data file corresponding to the tablespace is deleted before the tablespace is cleared, the database cannot be started or shut down normally.

You can use the following method to restore data (this method has been verified in oracle9i ):

In the following process, filename is a deleted data file. If there are multiple data files, it needs to be executed multiple times. tablespace_name is the name of the corresponding tablespace.

$ Sqlplus/nolog

SQL> conn/as sysdba;

If the database has been started, run the following line first:

SQL> shutdown abort

SQL> startup mount

SQL> alter database datafile 'filename' offline drop;

SQL> alter database open;

SQL> drop tablespace tablespace_name including contents;

Import and Export commands:

Importing and exporting Oracle Data imp/exp is equivalent to restoring and backing up oracle data. 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.

The following describes the Import and Export instances. (Note: you can export data directly under DOS without connecting to SQL/plus .)

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)

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.

Data Import

1. import data from 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.

2. Import table 1 in d: daochu. dmp

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

Example:

F: WorkOracle_Databackup> imp userid = test/test full = y file = inner_policy.dmp

Screen 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" 4 rows

Prepare to enable constraints...

Import is terminated successfully, but a warning is displayed.

Appendix 2:

Oracle cannot directly change the table owner. Export/Import can be used for this purpose.

First create import9.par,

The command is as follows: 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

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.