C:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.ora # listener.ora Network Configuration File: C:\app\Administrator\product\11.2.0\dbhome_1\network\admin\listener.ora # Generated by Oracle configuration tools. #listene_2是新建的测试连接,一般就是默认的listener,1521的那个 LISTENER_2 = #这是我建的新的连接,端口是1531作测试 (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = server-ip)(PORT = 1531)) #HOST直接用IP,域名,计算机名都是出错的地方 ) ) ADR_BASE_LISTENER_2 = C:\app\Administrator SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = CLRExtProc) (ORACLE_HOME = C:\app\Administrator\product\11.2.0\dbhome_1) (PROGRAM = extproc) (ENVS = "EXTPROC_DLLS=ONLY:C:\app\Administrator\product\11.2.0\dbhome_1\bin\oraclr11.dll") ) ) LISTENER = #这个是原始建的listener文件,1521,一般就用这个监听 (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = server-ip)(PORT = 1521)) ) ) ADR_BASE_LISTENER = C:\app\Administrator 从这个配置文件可以看出oracle是把所有的listen配置统一写在一个文件中,开启服务时,一起开启的 服务器只需要listener.ora文件即可,切记修改完后,一定要把监听服务重启 ----------------------------------------------------------------------------------- C:\Documents and Settings\Administrator>lsnrctl stop ----------------------------------------------------------------------------------- C:\Documents and Settings\Administrator>lsnrctl start ---------------------------------------------------------------------------------- 也可以在"我的电脑->右击manage->调出service
验证: C:\Documents and Settings\Administrator>netstat -ano Active Connections Proto Local Address Foreign Address State PID TCP 0.0.0.0:135 0.0.0.0:0 LISTENING 1060 TCP 0.0.0.0:445 0.0.0.0:0 LISTENING 4 TCP 0.0.0.0:1025 0.0.0.0:0 LISTENING 1512 TCP 0.0.0.0:1531 0.0.0.0:0 LISTENING 3472 TCP 0.0.0.0:2596 0.0.0.0:0 LISTENING 2848 TCP 0.0.0.0:2661 0.0.0.0:0 LISTENING 3420 TCP 0.0.0.0:3389 0.0.0.0:0 LISTENING 1916 TCP 10.8.116.232:139 0.0.0.0:0 LISTENING 4 TCP 10.8.116.232:1521 0.0.0.0:0 LISTENING 3588 TCP 10.8.116.232:1522 0.0.0.0:0 LISTENING 1112 TCP 10.8.116.232:1522 10.8.116.232:2662 ESTABLISHED 1112 TCP 10.8.116.232:1531 10.8.95.177:1141 ESTABLISHED 3472 TCP 10.8.116.232:1531 10.8.116.232:2660 ESTABLISHED 3472
如果服务器本机需要自测,则要需要配置tnsname.ora文件或利用oracle提供的net-manager工具,其实这是client的范畴
client安装好后需要配置net-manager,配置连接哪个数据库,哪个服务器信息
增加服务名(一般与连接的数据库一样,其实随意,就是一个名字)#C:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.ora # tnsnames.ora Network Configuration File: C:\app\Administrator\product\11.2.0\client_1\NETWORK\ADMIN\tnsnames.ora # Generated by Oracle configuration tools. 刚刚的步聚新建了ORCL的连接信息,数据库orcl, 服务器地址10.8.116.232, 监听端口1521 ORCL = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.8.116.232)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl) ) ) 由于服务器有两个数据库,可以直接编写一个连接服务器dh数据库的信息放在同一文件中,进行保存,如果服务器只有orcl,则不需要下面的这些信息 DH = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.8.116.232)(PORT = 1531)) ) (CONNECT_DATA = (SERVICE_NAME = dh) ) ) -------------------------------------------------------------------------------- Microsoft Windows [Version 5.2.3790] (C) Copyright 1985-2003 Microsoft Corp. C:\Documents and Settings\Administrator>sqlplus system/password@dh SQL*Plus: Release 11.2.0.1.0 Production on Fri Dec 18 18:32:13 2015 Copyright (c) 1982, 2010, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> select sysdate from dual; SYSDATE --------- 18-DEC-15 SQL> discon Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Pr oduction With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> conn terry/password@orcl Connected. SQL>
SQL基本操作:
client启动sqlplus C:\Documents and Settings\Administrator>sqlplus /nolog SQL*Plus: Release 11.2.0.1.0 Production on Fri Dec 18 18:51:33 2015 Copyright (c) 1982, 2010, Oracle. All rights reserved. 连接 SQL> conn terry/password@orcl Connected. 用户和权限 创建用户 create user 用户名 identified by 口令 [account lock| unlock] SQL> create user orcl identified by password; #一行写完 User created. SQL> create user jerry #分行写完 2 identified by password 3 account unlock; User created. 授权: grant 角色|权限 to 用户 SQL> grant connect to orcl; #orcl有连接和查看的权利,但没有写的权利 Grant succeeded. SQL> grant connect to jerry; Grant succeeded. SQL> grant resource to jerry; #jerry有操作数据库的权利 Grant succeeded. 建表 SQL> conn orcl/password@orcl Connected. SQL> select sysdate from dual; SYSDATE --------- 18-DEC-15 SQL> create table scores 2 (id number, 3 term varchar2(2)); create table scores * ERROR at line 1: ORA-01031: insufficient privileges SQL> discon Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Pr oduction With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> conn jerry/password@orcl Connected. SQL> create table scores 2 ( 3 id number, 4 term varchar2(2) 5 ); Table created. 更改密码 alter user 用户名 identified by 新密码 更改锁定状态 alter user 用户名 account lock|unlock 查询: select *|列名| from 表名 where 条件 order by 列名 SQL> select id from scores; ID ---------- 187186 插入: insert into 表名(列名1, 列名2 ..)values(值1,值2) SQL> insert into scores values 2 (187186,'dh'); 1 row created. 更新: update 表名 set 列名1=值, 列名2=值.....where 条件 SQL> update scores set 2 id=911,term='zj'; 1 row updated. SQL> select * from scores; ID TE ---------- -- 911 zj 删除: delete from 表名 where 条件 SQL> delete from scores; 1 row deleted. SQL> select * from scores; no rows selected SQL> commit; #只有提交了,才真正改了数据库中的表,否则其它用户还是见不到的val Commit complete. SQL> conn terry/password@orcl as sysdba #terry查看jerry建的表 Connected. SQL> select * from jerry.info; NAME SCORE -------- ---------- terry 187186
#注意的地方 1 client连数据库时格式是 sqlplus username/password@database client端database是必需有的,但是在服务器本地测试则可以不加,当服务器只有唯一数据库时 2 client由于我默认1521,但我服务器上有两个数据库,用的那一个不是1521导致tns adaptor出错 tnsname.ora的服务器地址,监听端口,数据库没填对 3 监听服务没有起来,导致 TNS no listener 4 server更改完listener,没有把监听服务重启,没生效 5 scott/tiger账户被锁,密码过期,导致连不上 6 client只需要tnsname.ora文件, server只需要listener.ora文件,概念有混