一、进入到sqlplus启动实例 (1)切换到oracle用户 [root@localhost ~]# su - oracle (2)打开监听 [oracle@localhost ~]$ lsnrctl start 还有以下命令: status;services;version;reload;可供选择运行; (3)进入sqlplus [oracle@localhost ~]$ sqlplus /nolog (4)连接到sysdba SQL> conn /as sysdba Connected to an idle instance. (5)启动数据库实例 SQL> startup ORACLE instance started.首选启动数据库 数据库启动使用startup命令,它有三种情况 第一种:不带参数,启动数据库实例并打开数据库,以便用户使用数据库,在多数情况下,使用这种方式! 第二种:带nomount参数,只启动数据库实例,但不打开数据库,在你希望创建一个新的数据库时使用,或者在你需要这样的时候使用! 第三种:带mount参数,在进行数据库更名的时候采用。这个时候数据库就打开并可以使用了! 如果你改了忘记了,可以利用如下方法重置: 1)进入cmd 2)sqlplus /nolog 3)alter user sys identified by 新密码; 2、新建的普通用户 1)sqlplus / nolog 2)SQL> conn /as sysdba 3) create user 用户名 identified by 密码; 4) grant connect,resource,dba to 用户名; 5) conn 用户名/密码 select * from nls_database_parameters; oracle创建表空间,创建用户以及授权 //创建临时表空间 create temporary tablespace test_temp tempfile '/u01/app/oracle/oradata/orcl/test_temp01.dbf' size 32M autoextend on next 32m maxsize 2048m extent management local; //创建数据表空间 create tablespace test_data logging datafile '/u01/app/oracle/oradata/orcl/test_data01.dbf' size 32m autoextend on next 32m maxsize 2048m extent management local; //创建用户并指定表空间 create user testserver_user identified by testserver_user default tablespace test_data temporary tablespace test_temp; //给用户授予权限 grant connect,resource,dba to testserver_user; //用户testserver_user连接 conn testserver_user/testserver_user //以后以该用户登录,创建的任何数据库对象都属于test_temp 和test_data表空间,这就不用在每创建一个对象给其指定表空间了。 --------------------------查看当前用户下信息(表空间,用户,视图,索引)--------------------- (1)查看当前用户及表空间 SQL> select username,default_tablespace from user_users; USERNAME DEFAULT_TABLESPACE ------------------------------ ------------------------------ TESTSERVER_USER TEST_DATA 查看当前用户的角色 SQL> select * from user_role_privs; USERNAME GRANTED_ROLE ADM DEF OS_ ------------------------------ ------------------------------ --- --- --- TESTSERVER_USER CONNECT NO YES NO TESTSERVER_USER DBA NO YES NO TESTSERVER_USER RESOURCE 查看用户下所有表 SQL> select * from user_tables; no rows selected 查看当前用户的系统权限和表级权限 SQL> select * from user_sys_privs; USERNAME PRIVILEGE ADM ------------------------------ ---------------------------------------- --- TESTSERVER_USER UNLIMITED TABLESPACE NO SQL> select * from user_tab_privs; no rows selected (2)用户 查看当前用户的缺省表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select * from user_role_privs; 查看当前用户的系统权限和表级权限 SQL>select * from user_sys_privs; SQL>select * from user_tab_privs; 显示当前会话所具有的权限 SQL>select * from session_privs; 显示指定用户所具有的系统权限 SQL>select * from dba_sys_privs where grantee='TESTSERVER_USER'; able_name') (3)表 查看用户下所有表 SQL> select * from user_tables; 查看名称包括log字符的表 SQL> select object_name,object_id from user_objects where instr(object_name,'LOG')>0; 查看某表的创建时间 SQL>select object_name,created from user_objects where bject_name=upper('&table_name'); 查看某表的大小 SQL>select sum(bytes)/(1024*1024) as "size(M)" from user_segments where segment_name=upper('&table_name'); 查看放在ORACLE的内存区里的表 SQL>select table_name,cache from user_tables where instr(cache,'Y')>0; 3、索引 查看索引个数和类别 SQL>select index_name,index_type,table_name from user_indexes order by table_name; 查看索引被索引的字段 SQL>select * from user_ind_columns where index_name=upper('&index_name'); 查看索引的大小 SQL>select sum(bytes)/(1024*1024) as "size(M)" from user_segments where segment_name=upper('&index_name'); 4、序列号 order by cc.position; 8、存储函数和过砙?@e? 查看序列号,last_number是当前值 SQL>select * from user_sequences; 5、视图 查看视图的名称 SQL>select view_name from user_views; 查看创建视图的select语句 SQL>set view_name,text_length from user_views; SQL>set long 2000; 说明:可以根据视图的text_length值设定set long 的大小 SQL>select text from user_views where view_name=upper('&view_name'); 6、同义词 查看同义词的名称 SQL>select * from user_synonyms; 7、约束条件 查看某表的约束条件 SQL>select constraint_name, constraint_type,search_condition, r_constraint_name from user_constraints where table_name = upper('&table_name'); SQL>select c.constraint_name,c.constraint_type,cc.column_name from user_constraints c,user_cons_columns cc where c.owner = upper('&table_owner') and c.table_name = upper('&table_name') and c.owner = cc.owner and c.constraint_name = cc.constraint_name order by cc.position; 8、存储函数和过程 ⒑凸 查看函数和过程的状态 SQL>select object_name,status from user_objects where object_type='FUNCTION'; SQL>select object_name,status from user_objects where object_type='PROCEDURE'; 查看函数和过程的源代码 SQL>select text from all_source where owner=user and name=upper('&plsql_name'); -----------------------------------------------查看用户权限--------------------------------------------------------- 查看所有用户: SELECT * FROM DBA_USERS; SELECT * FROM ALL_USERS; SELECT * FROM USER_USERS; 查看用户系统权限: SELECT * FROM DBA_SYS_PRIVS; SELECT * FROM USER_SYS_PRIVS; 查看用户对象或角色权限: SELECT * FROM DBA_TAB_PRIVS; SELECT * FROM ALL_TAB_PRIVS; SELECT * FROM USER_TAB_PRIVS; 查看所有角色: SELECT * FROM DBA_ROLES; 查看用户或角色所拥有的角色: SELECT * FROM DBA_ROLE_PRIVS; SELECT * FROM USER_ROLE_PRIVS; ------遇到no privileges on tablespace 'tablespace ' alter user userquota 10M[unlimited] on tablespace;