oracle 11g 常用命令:
1.sqlplus / as sysdba 进入sqlplus
2.vi /opt/oracle/product/11.2.0/rdbms/network/admin/listener.ora 设置监听
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.20.0.196)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
3.su - oracle
4.pwd
5. start
1.监听
启动监听
lsnrctl start
停止监听
lsnrctl stop
查看监听状态
lsnrctl status
2.启动
用oracle用户进入
su - oracle
运行sqlplus命令,进入sqlplus环境,nolog参数表示不登录;
sqlplus /nolog
以管理员模式进入
conn /as sysdba
启动数据库
startup;
停止数据库
SHUTDOWN IMMEDIATE
远程连接数据库
sqlplus /nolog conn sys/sys@IP:1521/orainstance as sysdba
也可以直接运行:
dbstart //启动数据库脚本 dbshut //停止数据库脚本 参考: STARTUP [FORCE][RESTRICT][NOMOUNT][MIGRATE][QUIET] [PFILE=] [MOUNT [EXCLUSIVE] x | OPEN ] SHUTDOWN
3.用户管理
创建用户
create user "username" identified by "userpassword" ;
注:后面可带表空间
删除用户
drop user “username” cascade;
注:cascade 参数是级联删除该用户所有对象,经常遇到如用户有对象而未加此参数则用户删不了的问题,所以习惯性的加此参数
授权
grant connect,resource,dba to "username" ;
查看当前用户的角色
select * from user_role_privs; select * from session_privs;
查看当前用户的系统权限和表级权限
select * from user_sys_privs; select * from user_tab_privs;
查询用户表
select username from dba_users;
修改用户口令
alter user "username" identified by "password";
显示当前用户
show user;
4.表及表空间
创建表空间
CREATE TABLESPACE data01 DATAFILE '/oracle/oradata/db/DATA01.dbf' SIZE 500M;
删除表空间
DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;
修改表空间大小
alter database datafile '/path/NADDate05.dbf' resize 100M;
增加表空间
ALTER TABLESPACE NEWCCS ADD DATAFILE '/u03/oradata/newccs/newccs04.dbf' SIZE 4896M;
查询数据库文件
select * from dba_data_files;
查询当前存在的表空间
select * from v$tablespace;
表空间情况
select tablespace_name,sum(bytes)/1024/1024 from dba_data_files group by tablespace_name;
查询表空间剩余空间
select tablespace_name,sum(bytes)/1024/1024 from dba_free_space group by tablespace_name;
查看表结构
desc table;
修改连接数:要重启数据库
alter system set processes=1000 scope=spfile; shutdown immediate; startup;
查看用户当前连接数
select count(*) from sys.v_$session; PL/SQL [DECLARE /*申明部分,一般是变量及常量*/] [ BEGIN /*执行部分,流程结构控制,SQL部分*/] [EXCEPTION /*异常处理部分*/] END SET SERVEROUTPUT ON //打开输出开关 BEGIN DBMS_OUTPUT.PUT_LINE('Hello world!'); //输出结果 END;