1. Create a user
CREATE USER username IDENTIFIED BY password DEFAULT TABLESPACE tablespaceName;
2. Empowerment
grant dba to username;--give dba permission
GRANT CONNECT, RESOURCE, CREATE VIEW TO username IDENTIFIED BY password;--Give some permissions
3. Export
exp username/password@dbnamefile=*.dmp log=logPath.log
If the error oracle 12514 error is reported when this command is executed, you can try the following command
exp username/password@ip:端口/dbnamefile=*.dmp log=logPath.log
The solution for oracle 11g empty table is also exported
http://blog.51cto.com/wanwentao/545154
4. Import (specify tablespace)
imp username/password@dbname file=*.dmp tablespaces=tablespaceName fromuser=expusername touser=impusername log=logPath.log
When executing the imp command, the import of the table with the clob blob field often fails, indicating that the table space does not exist. The quickest solution is to create these tables with large fields before importing, and then import them. Add ignore=y to the import statement.
5. Oracle 11g is perfectly exported to oracle10g_Baidu experience
http://jingyan.baidu.com/article/29697b9137d421ab21de3c47.html
6. Delete User
drop user mpmtj cascade;
Forcibly disconnect the user connection method:
select sid,serial# from v$session where username='用户名';
alter system kill session 'sid,serial';
7. Modify the character set (reproduced http://jingyan.baidu.com/article/c1465413af2fb20bfcfc4c3e.html )
Character set change for oracle database
A. Oracle server side character set query
select userenv('language') from dual
Where NLS_CHARACTERSET is the server side character set
NLS_LANGUAGE is the character display form on the server side
B. Query the character set of the oracle client side
$echo $NLS_LANG
If you find that the data you select is garbled, please configure the character set on the client side to the same character set as the Linux operating system. If there are still garbled characters, there may be a problem with the data in the database, or there is a problem with the configuration of the oracle server.
C, server-side character set modification
*****************************************************************
* Change the character set step method (WE8ISO8859P1 --> ZHS16GBK) *
*****************************************************************
SQL>
Start the database in RESTRICTED mode and make character set changes:
SQL> conn /as sysdba
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;
System altered.
SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
System altered.
SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=0;
System altered.
SQL> alter database open;
Database altered.
SQL> ALTER DATABASE CHARACTER SET ZHS16GBK;
ALTER DATABASE CHARACTER SET ZHS16GBK
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set
提示我们的字符集:新字符集必须为旧字符集的超集,这时我们可以跳过超集的检查做更改:
SQL> ALTER DATABASE character set INTERNAL_USE ZHS16GBK;
Database altered.
SQL> select * from v$nls_parameters;
略
19 rows selected.
重启检查是否更改完成:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL> select * from v$nls_parameters;
略
19 rows selected.
正确设置ORACLE客户端字符集的方法:
oracle客户端字符集设置需要和服务器端一致,否则会出现乱码问题。
首先连接服务器,查询服务器端设置:
select * from v$nls_parameters;
找到:
NLS_LANGUAGE
NLS_TERRITORY
NLS_CHARACTERSET
环境变量nls_lang便是由这三部分组成
NLS_LANG = language_territory.charset
比如:AMERICAN_AMERICA.ZHS16GBK
8.删除用户所有的表
select 'drop table '||table_name||' ;' from all_tables where owner='user_name';--owner字段是大写
9.占用cpu大的语句
select * from (select sql_text,sql_id,cpu_time from v$sql order by cpu_time desc) where rownum<=10 order by rownum asc;
select * from (select sql_text,sql_id,cpu_time from v$sqlarea order by cpu_time desc) where rownum<=10 order by rownum asc;
10.查询某段时间某个用户执行时间长的sql
select executions, cpu_time/1e6 as cpu_sec, elapsed_time/1e6 as elapsed_sec, round(elapsed_time/sqrt(executions)) as important, v.*
from v$sql v
where executions > 10 and last_active_time>to_date('2016-11-22 18:00','yyyy-mm-dd hh24:mi') and last_active_time<to_date('2016-11-22 20:00','yyyy-mm-dd hh24:mi') and parsing_schema_name='MBP1'
order by important desc;
11.查看用户信息
select * from dba_users;
12.创建表空间
CREATE TABLESPACE MAINHR
DATAFILE 'C:\Users\chen\oracle_tablespace\MAINHR_FILE01.ora' SIZE 100M REUSE,'C:\Users\chen\oracle_tablespace\MAINHR_FILE02.ora' SIZE 100M REUSE
DEFAULT STORAGE(INITIAL 500K NEXT 500K PCTINCREASE 20);