• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置

互联网 diligentman 4天前 8次浏览

初始环境:阿里云轻量应用服务器已经安装Oracle19c
具体目标:配置Oracle Database 19c

目录

  • 第一步:切换到Oracle命令行
  • 第二步:新建用户和表空间
  • 第三步:切换用户
  • 第四步:在当前用户下创建一些表
  • 第五步:给刚才的表添加一些数据
  • 第六步:下载最新版的instantclient
  • 第七步:Navicat配置

第一步:切换到Oracle命令行

1.修改root用户密码,千万记得这一步,不然你会后悔的。
执行命令 passwd ,输入两次123456,就可以了。
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
2.切换到oracle用户下,执行命令su – oracle
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
3.查看监听状态,执行命令 lsnrctl status
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
监听启动,执行命令 lsnrctl start
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
监听关闭,执行命令 lsnrctl stop

4.登录oracle数据库,执行命令sqlplus / as sysdba
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置

第二步:新建用户和表空间

1.启动实例,执行命令 startup
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置

关闭实例,执行命令 shutdown

2.创建临时表空间:

--查询临时表空间文件的绝对路径。如果需要的话,可以通过查询来写定绝对路径。一般用${ORACLE_HOME}就可以了  
select name from v$tempfile;  
create temporary tablespace TESTLEAF_TEMP tempfile '${ORACLE_HOME}oradataTESTLEAF_TEMP.bdf' size 100m reuse autoextend on next 20m maxsize unlimited; 

阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
3.创建正式表空间:

--查询用户表空间文件的绝对路径:
select name from v$datafile;
create tablespace TESTLEAF datafile '${ORACLE_HOME}oradataTESTLEAF.dbf' size 100M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);

阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
4.创建用户和密码,指定上边创建的临时表空间和表空间(创建用户的时候用户名以C##开头即可,防止提示用户名无效):

create user C##TESTLEAF identified by 123456 default tablespace TESTLEAF temporary tablespace TESTLEAF_TEMP;

阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
5.修改用户名名称
查询需要修改的用户名的编号:

select user#,name from user$;

阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
(取对应的user#,这里user#等于113)
修改用户名称:

update user$ set name='TESTLEAF' where user#=113;

阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
6.解决Oracle修改用户名后,再次修改该用户密码,会报‘找不到该用户’的问题:

ALTER SYSTEM FLUSH SHARED_POOL;

阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
7.修改该用户对应的密码:

ALTER USER TESTLEAF IDENTIFIED BY 123456;

阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
8.用户赋权:

grant dba to TESTLEAF;
grant connect,resource to TESTLEAF;
grant select any table to TESTLEAF;
grant delete any table to TESTLEAF;
grant update any table to TESTLEAF;
grant insert any table to TESTLEAF;
#操作表空间的权限
grant unlimited tablespace to TESTLEAF;

阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
9.查看用户所有权限:

select * from dba_sys_privs where grantee = 'TESTLEAF';
select * from dba_role_privs where grantee = 'TESTLEAF';

第三步:切换用户

1.切换到刚刚创建的用户(用户名+密码):

conn TESTLEAF/123456;

2.检查当前用户:

show user;

阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置

第四步:在当前用户下创建一些表

1.创建表Customers

CREATE TABLE Customers
(
  cust_id      char(10)  NOT NULL ,
  cust_name    char(50)  NOT NULL ,
  cust_address char(50)  NULL ,
  cust_city    char(50)  NULL ,
  cust_state   char(5)   NULL ,
  cust_zip     char(10)  NULL ,
  cust_country char(50)  NULL ,
  cust_contact char(50)  NULL ,
  cust_email   char(255) NULL 
);

2.创建表OrderItems

CREATE TABLE OrderItems
(
  order_num  int          NOT NULL ,
  order_item int          NOT NULL ,
  prod_id    char(10)     NOT NULL ,
  quantity   int          NOT NULL ,
  item_price decimal(8,2) NOT NULL 
);

3.创建表Orders

CREATE TABLE Orders
(
  order_num  int      NOT NULL ,
  order_date date     NOT NULL ,
  cust_id    char(10) NOT NULL 
);

4.创建表Products

CREATE TABLE Products
(
  prod_id    char(10)      NOT NULL ,
  vend_id    char(10)      NOT NULL ,
  prod_name  char(255)     NOT NULL ,
  prod_price decimal(8,2)  NOT NULL ,
  prod_desc  varchar(1000) NULL 
);

5.创建表Vendors

CREATE TABLE Vendors
(
  vend_id      char(10) NOT NULL ,
  vend_name    char(50) NOT NULL ,
  vend_address char(50) NULL ,
  vend_city    char(50) NULL ,
  vend_state   char(5)  NULL ,
  vend_zip     char(10) NULL ,
  vend_country char(50) NULL 
);

6.定义主键

ALTER TABLE Customers ADD CONSTRAINT PK_Customers PRIMARY KEY (cust_id);
ALTER TABLE OrderItems ADD CONSTRAINT PK_OrderItems PRIMARY KEY (order_num, order_item);
ALTER TABLE Orders ADD CONSTRAINT PK_Orders PRIMARY KEY (order_num);
ALTER TABLE Products ADD CONSTRAINT PK_Products PRIMARY KEY (prod_id);
ALTER TABLE Vendors ADD CONSTRAINT PK_Vendors PRIMARY KEY (vend_id);

7.定义外键

ALTER TABLE OrderItems
ADD CONSTRAINT FK_OrderItems_Orders FOREIGN KEY (order_num) REFERENCES Orders (order_num);
ALTER TABLE OrderItems
ADD CONSTRAINT FK_OrderItems_Products FOREIGN KEY (prod_id) REFERENCES Products (prod_id);
ALTER TABLE Orders
ADD CONSTRAINT FK_Orders_Customers FOREIGN KEY (cust_id) REFERENCES Customers (cust_id);
ALTER TABLE Products
ADD CONSTRAINT FK_Products_Vendors FOREIGN KEY (vend_id) REFERENCES Vendors (vend_id);

第五步:给刚才的表添加一些数据

1.给表Customers添加数据

INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000001', 'Village Toys', '200 Maple Lane', 'Detroit', 'MI', '44444', 'USA', 'John Smith', 'sales@villagetoys.com');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact)
VALUES('1000000002', 'Kids Place', '333 South Lake Drive', 'Columbus', 'OH', '43333', 'USA', 'Michelle Green');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000003', 'Fun4All', '1 Sunny Place', 'Muncie', 'IN', '42222', 'USA', 'Jim Jones', 'jjones@fun4all.com');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000004', 'Fun4All', '829 Riverside Drive', 'Phoenix', 'AZ', '88888', 'USA', 'Denise L. Stephens', 'dstephens@fun4all.com');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state, cust_zip, cust_country, cust_contact)
VALUES('1000000005', 'The Toy Store', '4545 53rd Street', 'Chicago', 'IL', '54545', 'USA', 'Kim Howard');

2.给表Vendors添加数据

INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES('BRS01','Bears R Us','123 Main Street','Bear Town','MI','44444', 'USA');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES('BRE02','Bear Emporium','500 Park Street','Anytown','OH','44333', 'USA');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES('DLL01','Doll House Inc.','555 High Street','Dollsville','CA','99999', 'USA');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES('FRB01','Furball Inc.','1000 5th Avenue','New York','NY','11111', 'USA');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES('FNG01','Fun and Games','42 Galaxy Road','London', NULL,'N16 6PS', 'England');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city, vend_state, vend_zip, vend_country)
VALUES('JTS01','Jouets et ours','1 Rue Amusement','Paris', NULL,'45678', 'France');

3.给表Products添加数据

INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('BR01', 'BRS01', '8 inch teddy bear', 5.99, '8 inch teddy bear, comes with cap and jacket');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('BR02', 'BRS01', '12 inch teddy bear', 8.99, '12 inch teddy bear, comes with cap and jacket');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('BR03', 'BRS01', '18 inch teddy bear', 11.99, '18 inch teddy bear, comes with cap and jacket');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('BNBG01', 'DLL01', 'Fish bean bag toy', 3.49, 'Fish bean bag toy, complete with bean bag worms with which to feed it');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('BNBG02', 'DLL01', 'Bird bean bag toy', 3.49, 'Bird bean bag toy, eggs are not included');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('BNBG03', 'DLL01', 'Rabbit bean bag toy', 3.49, 'Rabbit bean bag toy, comes with bean bag carrots');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('RGAN01', 'DLL01', 'Raggedy Ann', 4.99, '18 inch Raggedy Ann doll');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('RYL01', 'FNG01', 'King doll', 9.49, '12 inch king doll with royal garments and crown');
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price, prod_desc)
VALUES('RYL02', 'FNG01', 'Queen doll', 9.49, '12 inch queen doll with royal garments and crown');

4.给表Orders添加数据

INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20005, TO_DATE('2012-05-01', 'yyyy-mm-dd'), '1000000001');
INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20006, TO_DATE('2012-01-12', 'yyyy-mm-dd'), '1000000003');
INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20007, TO_DATE('2012-01-30', 'yyyy-mm-dd'), '1000000004');
INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20008, TO_DATE('2012-02-03', 'yyyy-mm-dd'), '1000000005');
INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20009, TO_DATE('2012-02-08', 'yyyy-mm-dd'), '1000000001');

5.给表OrderItems添加数据

INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20005, 1, 'BR01', 100, 5.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20005, 2, 'BR03', 100, 10.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20006, 1, 'BR01', 20, 5.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20006, 2, 'BR02', 10, 8.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20006, 3, 'BR03', 10, 11.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 1, 'BR03', 50, 11.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 2, 'BNBG01', 100, 2.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 3, 'BNBG02', 100, 2.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 4, 'BNBG03', 100, 2.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 5, 'RGAN01', 50, 4.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 1, 'RGAN01', 5, 4.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 2, 'BR03', 5, 11.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 3, 'BNBG01', 10, 3.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 4, 'BNBG02', 10, 3.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 5, 'BNBG03', 10, 3.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20009, 1, 'BNBG01', 250, 2.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20009, 2, 'BNBG02', 250, 2.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20009, 3, 'BNBG03', 250, 2.49);

第六步:下载最新版的instantclient

1.由于Oracle官网下载较慢,于是提供了下方的百度网盘链接。
链接: https://pan.baidu.com/s/1CWR5ka5z7WDZ91iM0UsUMg 提取码: leaf
感兴趣的小伙伴也可以按照下面的方法在Oracle官网进行下载。
2.打开网站:https://www.oracle.com/database/technologies/instant-client.html
3.点击“Download”:
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
4.点击“Instant Client for Microsoft Windows (x64)”:
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
5.依次点击下载:Basic Package、SQL*Plus Package、SDK Package;
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
6.下载后进行解压,放进同一个文件夹
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置

第七步:Navicat配置

1.打开Navicat,点击“工具”》“选项”:
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
2.点击“环境”,选择好刚才下载的文件夹里面对应的sqlplus.exe文件和oci.dll文件,点击“确定”,并重启Navicat,这样在Navicat中就可以对Oracle数据库使用sqlplus命令行界面了。
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
3.阿里云防火墙添加1521端口
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
不然就会出现如下错误:ORA-12170
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
4.服务名查询
在数据库中输入查询语句,
select global_name from global_name;
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
我这里是ORCLCDB,把这个记住。

5.Navicat使用刚才创建的用户新建连接
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置
6.找到与该用户名相同的表空间,可以看到刚才创建的五张表,里面的数据也别无二致;
阿里云轻量应用服务器Linux-Centos7下Oracle19c的配置

免责声明:
1.编写此文是为了更好地学习Oracle的配置,如果损害了有关人的利益,请联系删除;
2.如果文中描述欠妥,请在评论中进行指正;
3.文字编写不易,若感觉有用,点赞收藏关注会让博主很开心哦;
4.此外,本文支持任何形式的转载,转载请注明出处,非常感谢!!!
本文源自:https://blog.csdn.net/testleaf/article/details/109096654
博客园cnblogs同号。


喜欢 (0)