oracle 進階 (1)

來源:互聯網
上載者:User

標籤:oracle   伺服器   筆記本   copyright   


準備從零開始學習oracle。

我說過2016年堅持每周寫一篇技術部落格。那麼從現在開始。

 

今天遇到一個弱爆了的問題:

前幾天換了一台筆記本,在新筆記本上面安裝了oracle 11g R2。使用dbca安裝完資料庫沒有報錯,就關電腦睡覺了,今天想著開始學習oracle,實現OCP進階,結果剛開始就犯了一個低級錯誤。

 

我登陸伺服器,

[[email protected] ~]# su - oracle[[email protected] ~]$


切換到oracle使用者之後,啟動資料庫

[

[email protected] ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on 星期一 1月 11 19:58:132016 Copyright (c) 1982, 2009, Oracle.  All rights reserved. 已串連到空閑常式。 SQL> startupORACLE 常式已經啟動。 Total System Global Area  839282688 bytesFixed Size                  2217992 bytesVariable Size             494929912 bytesDatabase Buffers          339738624 bytesRedo Buffers                2396160 bytes資料庫裝載完畢。資料庫已經開啟。


 

之後查看1521連接埠狀態

[[email protected] ~]$ netstat -nat | grep 1521[[email protected] ~]$


奇怪,1521連接埠沒監聽。想了半天定位是監聽沒起來,於是啟動監聽

[[email protected] ~]$ lsnrctl start LSNRCTL for Linux: Version 11.2.0.1.0 -Production on 11-1月 -2016 20:43:10 Copyright (c) 1991, 2009, Oracle.  All rights reserved. 啟動/u01/app/oracle/product/11.2.0/db_1/bin/tnslsnr: 請稍候... TNSLSNR for Linux: Version 11.2.0.1.0 -Production系統參數檔案為/u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora寫入/u01/app/oracle/diag/tnslsnr/oracle/listener/alert/log.xml的日誌資訊監聽: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle)(PORT=1521))) 正在串連到 (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle)(PORT=1521)))LISTENER 的 STATUS------------------------別名                      LISTENER版本                      TNSLSNRfor Linux: Version 11.2.0.1.0 - Production啟動日期                  11-1月 -201620:43:10正常已耗用時間              0 天 0 小時 0 分 20 秒追蹤層級                  off安全性                    ON: LocalOS AuthenticationSNMP                      OFF監聽程式參數檔案          /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora監聽程式記錄檔         /u01/app/oracle/diag/tnslsnr/oracle/listener/alert/log.xml監聽端點概要... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle)(PORT=1521)))監聽程式不支援服務命令執行成功


 

重新查看連接埠狀態:


[email protected] ~]$ netstat -nat | grep 1521tcp       0      0 172.20.0.20:64165           172.20.0.20:1521            TIME_WAIT   tcp       0      0 :::1521                     :::*                        LISTEN


 

好了,連接埠啟動起來了,由於我是學習oracle,肯定要查看當前資料庫有哪些使用者:

 

SQL> select username fromall_users;   USERNAME------------------------------BIPMSHIXOEHRSCOTTOWBSYS_AUDITOWBSYSAPEX_030200APEX_PUBLIC_USER USERNAME------------------------------FLOWS_FILESMGMT_VIEWSYSMANSPATIAL_CSW_ADMIN_USRSPATIAL_WFS_ADMIN_USRMDDATAMDSYSSI_INFORMTN_SCHEMAORDPLUGINSORDDATAORDSYS USERNAME------------------------------OLAPSYSANONYMOUSXDBCTXSYSEXFSYSXS$NULLWMSYSAPPQOSSYSDBSNMPORACLE_OCMDIP USERNAME------------------------------OUTLNSYSTEMSYS 已選擇36行。


 

於是切換到普通使用者,想要學習一些對資料庫表的基本增刪改查,問題來了

 

SQL> alter user scott identified by"123456"; 使用者已更改。 SQL> conn scott/scottERROR:ORA-28000: 帳戶已被鎖定  警告: 您不再串連到 ORACLE。 SQL> alter user scott account unlock;SP2-0640: 未串連SQL> exit


 

奇怪,為什麼一直報這個錯呢?我已經解鎖並且重設了密碼呀,而且後面不管我執行什麼樣的命令都報SP2-0640: 未串連

 

資料庫重啟問題依然存在,懷疑自己的執行個體是不是建立的有問題,從日誌排查吧,看看日誌裡面有沒有報錯,奇怪的是,當我切換到ORACLE_HOME目錄下想要查看日誌時,報錯出現了

 

[[email protected] db_1]$ cd network/admin/[[email protected] admin]$ lslistener.ora  samples shrept.lst[[email protected] admin]$ cd ../[[email protected] network]$ lsadmin doc  install  jlib lib  log  mesg tools  trace[[email protected] network]$ cd trace/[[email protected] trace]$ ls[[email protected] trace]$ cd ../log/[[email protected] log]$ lssqlnet.log[[email protected] log]$ less sqlnet.log Directory does not exist for read/write[/u01/app/oracle/product/11.2.0/db_1/log] [/u01/app/oracle/product/11.2.0/db_1/log/diag/clients]


 

問題原因找到了,原來是目錄不存在,奇怪,按理說安裝資料庫的時候這些目錄應該自動建立的,先不管了,手動建立這些目錄。

 

[[email protected]]$ pwd/u01/app/oracle/product/11.2.0/db_1/network/log[[email protected] log]$ cd ../log/[[email protected] log]$ lssqlnet.log[[email protected] log]$ mkdir diag[[email protected] log]$ lsdiag sqlnet.log[[email protected] log]$ cd diag/[[email protected] diag]$ ls[[email protected] diag]$ mkdir client[[email protected] diag]$ lsclient


 

重啟資料庫

 

[[email protected] ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on 星期一 1月 11 20:51:212016 Copyright (c) 1982, 2009, Oracle.  All rights reserved.  串連到: Oracle Database 11g Enterprise EditionRelease 11.2.0.1.0 - 64bit ProductionWith the Partitioning, OLAP, Data Miningand Real Application Testing options SQL> shutdown immediate;資料庫已經關閉。已經卸載資料庫。ORACLE 常式已經關閉。

 

為了保險起見,先將資料庫啟動到mount狀態,(實際這裡應該是先啟動到nomount狀態,再啟動到mount狀態,之後再開啟資料庫,手抖打錯了,將錯就錯吧)

SQL> startup mount;ORACLE 常式已經啟動。 Total System Global Area  839282688 bytesFixed Size                  2217992 bytesVariable Size             494929912 bytesDatabase Buffers          339738624 bytesRedo Buffers                2396160 bytes資料庫裝載完畢。SQL> alter database open; 資料庫已更改。


 

之前登陸失敗,使用者已經被鎖住,解鎖使用者並重設密碼為tiger

SQL> alter user scott account unlockidentified by tiger; 使用者已更改。 SQL> alter user scott account unlock; 使用者已更改。 SQL> conn scott/tiger;已串連。 查看目前使用者: SQL> show user;USER 為 "SCOTT"


 

查看目前使用者下有哪些表:

SQL> select TABLE_NAME from user_tables; TABLE_NAME------------------------------SALGRADEBONUSEMPDEPT SQL>


 

問題解決。


本文出自 “7159900” 部落格,請務必保留此出處http://7169900.blog.51cto.com/7159900/1733956

oracle 進階 (1)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.