第一步. 登录数据库服务器
使用ssh工具(如果是windows操作系统请下载使用putty)登录数据库服务器(RedHat 5.X), 必须使用oracle用户登录(非root用户,这里需要注意):
Loopers-MacBook-Pro:Desktop looper_lvy$ ssh oracle@192.168.1.136
oracle@192.168.1.136's password:
Last login: Fri Oct 14 11:00:28 2016 from 192.168.1.107
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
[oracle@Oracle10g ~]$ whoami
oracle
第二步. 登录sqlplus, 关闭数据库,以nomount方式启动:
[oracle@Oracle10g ~]$ sqlplus "/ as sysdba"
SQL> shutdown immediate;
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 557842432 bytes
Fixed Size 2022312 bytes
Variable Size 205522008 bytes
Database Buffers 348127232 bytes
Redo Buffers 2170880 bytes
Database mounted.
Database opened.
第三步. 创建表空间:
SQL> create tablespace CXNT2_TEST logging datafile '/opt/oracle/oradata/orcl/CXNT2_TEST.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local;
Tablespace created.
第四步. 创建用户及设置用户相关权限:
4.1 创建用户:
SQL> create user cxnt2_test identified by password default tablespace CXNT2_TEST;
User created.
4.2 设置用户权限:
SQL> grant connect,resource,dba to cxnt2_test;
Grant succeeded.
4.3 重启生效:
SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.
Total System Global Area 557842432 bytes
Fixed Size 2022312 bytes
Variable Size 209716312 bytes
Database Buffers 343932928 bytes
Redo Buffers 2170880 bytes
Database mounted.
补充:删除表空间及相关用户:
SQL> drop user cxnt2_test cascade;
User dropped.
SQL> DROP TABLESPACE CXNT2_TEST INCLUDING CONTENTS AND DATAFILES;
Tablespace dropped.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.
Total System Global Area 557842432 bytes
Fixed Size 2022312 bytes
Variable Size 218104920 bytes
Database Buffers 335544320 bytes
Redo Buffers 2170880 bytes
Database mounted.
Database opened.
FAQ: 如果oracle数据库中文乱码,请修改oracle字符集
>shutdown immediate;
>startup mount;
>ALTER SESSION SET SQL_TRACE=TRUE;
>ALTER SYSTEM ENABLE RESTRICTED SESSION;
>ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
>ALTER SYSTEM SET AQ_TM_PROCESSES=0;
>ALTER DATABASE OPEN;
>set linesize 120;
>alter database character set zhs16gbk;
ORA-12712: new character set must be a superset of old character set
RROR at line 1:
>ALTER DATABASE character set INTERNAL_USE zhs16gbk;
>ALTER SESSION SET SQL_TRACE=FALSE;
>shutdown immediate;
>STARTUP;
<b>还需要修改系统参数</b>:
查看环境变量 echo $NLS_LANG, 查看数据库字符集 select userenv('language') from dual; 如果二者不一致,修改其一使二者一致, 修改NLS_LNAG,有两种方式:
临时修改 在当前登录终端执行export NLS_LANG=XX (XX:表示数据库字符集)
本地登录退出后失效;永久修改 修改.bash_profile,在文件中加入export NLS_LANG=XX (XX:表示数据库字符集)
重新登录后永久生效;