欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

oracle中scott用户的创建

程序员文章站 2022-05-29 12:03:06
oracle11g中没有scott用户的解决,通过创建scott.sql文件,然后授予权限,解锁,修改密码等一系列的操作来完成账号建立 ......

 

原创作品,转载请在文章开头显眼位置注明出处:https://www.cnblogs.com/sunshine5683/p/10046716.html

今天,接着上次的学习进度继续前进,在此过程中,使用scott用户登录时候显示scott用户不存在,于是进行scott用户的解锁操作

sql> alter user scott account unlock;
alter user scott account unlock
           *
第 1 行出现错误:

ora-01918: 用户 'scott' 不存在

 

由上面的过程可以很轻松的看出,scott用户不存在,然后进行scott用户的创建,网上有好多类似的创建方法,说在某个目录下面可以找到scott.sql文件,然后用相应的命令执行此操作便可以,但是在实际操作的过程中并没有发现该文件,可能是本人安装的数据库中本来就没有的原因,本人主要查找的目录有:

 usr/local/oracle/product/rdbms/admin/   目录,因为本人的数据库就在此目录下,并没有找到,那么就继续构造该文件

首先:在客户机上建立一个txt文件,然后在文件中输入以下内容:

 1 rem copyright (c) 1990 by oracle corporation
 2 rem name
 3 rem    utlsampl.sql
 4 rem  function
 5 rem  notes
 6 rem  modified
 7 rem    gdudey       06/28/95 -  modified for desktop seed database
 8 rem    glumpkin   10/21/92 -  renamed from sqlbld.sql
 9 rem    blinden   07/27/92 -  added primary and foreign keys to emp and dept
10 rem    rlim       04/29/91 -          change char to varchar2
11 rem    mmoore       04/08/91 -          use unlimited tablespace priv
12 rem    pritto       04/04/91 -          change sysdate to 13-jul-87
13 rem   mendels     12/07/90 - bug 30123;add to_date calls so language independent
14 rem
15 rem
16 rem $header: utlsampl.sql 7020100.1 94/09/23 22:14:24 cli generic<base> $ sqlbld.sql
17 rem
18 set termout off
19 set echo off
20 
21 rem congdon    invoked in rdbms at build time.     29-dec-1988
22 rem oates:     created: 16-feb-83
23 
24 grant connect,resource,unlimited tablespace to scott identified by tiger;
25 alter user scott default tablespace users;
26 alter user scott temporary tablespace temp;
27 connect scott/tiger
28 drop table dept;
29 create table dept
30        (deptno number(2) constraint pk_dept primary key,
31     dname varchar2(14) ,
32     loc varchar2(13) ) ;
33 drop table emp;
34 create table emp
35        (empno number(4) constraint pk_emp primary key,
36     ename varchar2(10),
37     job varchar2(9),
38     mgr number(4),
39     hiredate date,
40     sal number(7,2),
41     comm number(7,2),
42     deptno number(2) constraint fk_deptno references dept);
43 insert into dept values
44     (10,'accounting','new york');
45 insert into dept values (20,'research','dallas');
46 insert into dept values
47     (30,'sales','chicago');
48 insert into dept values
49     (40,'operations','boston');
50 insert into emp values
51 (7369,'smith','clerk',7902,to_date('17-12-1980','dd-mm-yyyy'),800,null,20);
52 insert into emp values
53 (7499,'allen','salesman',7698,to_date('20-2-1981','dd-mm-yyyy'),1600,300,30);
54 insert into emp values
55 (7521,'ward','salesman',7698,to_date('22-2-1981','dd-mm-yyyy'),1250,500,30);
56 insert into emp values
57 (7566,'jones','manager',7839,to_date('2-4-1981','dd-mm-yyyy'),2975,null,20);
58 insert into emp values
59 (7654,'martin','salesman',7698,to_date('28-9-1981','dd-mm-yyyy'),1250,1400,30);
60 insert into emp values
61 (7698,'blake','manager',7839,to_date('1-5-1981','dd-mm-yyyy'),2850,null,30);
62 insert into emp values
63 (7782,'clark','manager',7839,to_date('9-6-1981','dd-mm-yyyy'),2450,null,10);
64 insert into emp values
65 (7788,'scott','analyst',7566,to_date('13-jul-87')-85,3000,null,20);
66 insert into emp values
67 (7839,'king','president',null,to_date('17-11-1981','dd-mm-yyyy'),5000,null,10);
68 insert into emp values
69 (7844,'turner','salesman',7698,to_date('8-9-1981','dd-mm-yyyy'),1500,0,30);
70 insert into emp values
71 (7876,'adams','clerk',7788,to_date('13-jul-87')-51,1100,null,20);
72 insert into emp values
73 (7900,'james','clerk',7698,to_date('3-12-1981','dd-mm-yyyy'),950,null,30);
74 insert into emp values
75 (7902,'ford','analyst',7566,to_date('3-12-1981','dd-mm-yyyy'),3000,null,20);
76 insert into emp values
77 (7934,'miller','clerk',7782,to_date('23-1-1982','dd-mm-yyyy'),1300,null,10);
78 drop table bonus;
79 create table bonus
80     (
81     ename varchar2(10)    ,
82     job varchar2(9)  ,
83     sal number,
84     comm number
85     ) ;
86 drop table salgrade;
87 create table salgrade
88       ( grade number,
89     losal number,
90     hisal number );
91 insert into salgrade values (1,700,1200);
92 insert into salgrade values (2,1201,1400);
93 insert into salgrade values (3,1401,2000);
94 insert into salgrade values (4,2001,3000);
95 insert into salgrade values (5,3001,9999);
96 commit;
97 
98 set termout on
99 set echo on

 

其次,将新建的txt文件保存为.sql文件,注意后缀名隐藏的话打开计算机----组织----文件夹选项----在隐藏已知文件的扩展名前面的√去掉,然后将.txt改成.sql

 

再次,将刚刚保存好的sql文件拷贝到linux服务器的 usr/local/oracle/product/rdbms/admin/目录下,可以看看创建时间

oracle中scott用户的创建

oracle中scott用户的创建

 

 然后,使用命令:su - oracle -c 'sqlplus / as sysdba'切换到sqlplus命令行模式,执行以下语句

@$oracle_home/rdbms/admin/scott.sql

执行前:

oracle中scott用户的创建

执行:

oracle中scott用户的创建

执行后:

oracle中scott用户的创建

oracle中scott用户的创建

到此,scott用户的创建已经完成。

现在使用刚刚创建好的scott用户登录,但是发现密码不知道是什么,并不是tiger,然后使用sys用户对scott用户重新设置密码,如下:

oracle中scott用户的创建

 

 最终顺利完成!