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/目錄下,可以看看創建時間
然後,使用命令:su - oracle -c 'sqlplus / as sysdba'切換到sqlplus命令行模式,執行以下語句
@$ORACLE_HOME/rdbms/admin/scott.sql
執行前:
執行:
執行後:
到此,scott用戶的創建已經完成。
現在使用剛剛創建好的scott用戶登錄,但是發現密碼不知道是什麼,並不是tiger,然後使用sys用戶對scott用戶重新設置密碼,如下:
最終順利完成!