Oracle installation and basic use, connect to Oracle with Navicat

Install virtual machine

For learning to use, I strongly recommend installing Oracle on a virtual machine. If it crashes, just roll back the virtual machine with the help of a snapshot. In this blog, I also take Oracle on a virtual machine as an example.

https://blog.csdn.net/qq_43290318/article/details/107704675

Search a lot of online tutorials, you can also refer to the above blog. But note that when partitioning the system: The partition for installing Oracle on Linux is at least 20G, otherwise the space will be insufficient! Repeat again, whatever partition you install Oracle to, but that partition has at least 20G of space !

After the entire Oracle is installed, it can account for more than ten gigabytes. In the above blog, I created a new /data partition when I added the system partition to store my own miscellaneous things. I suggest that students who read this blog create an additional partition and allocate at least 20G in size, and then install Oracle to this new partition. The best name is also /data, because the following installation process also uses /data as an example.

Install Oracle

https://www.cnblogs.com/mmzs/p/9033112.html

This blog describes in detail the entire Oracle installation process and various pits, and I followed the installation. The version is the same as the above version, just do it directly. The installation of the new version is a bit different.

Note that after downloading the Oracle image from the official website, there is no need to copy it from the host to the virtual machine. This can be achieved through the Vmware shared folder! ! !

Oracle basic commands

In the terminal operation of the virtual machine:

# 在Linux上切换系统用户为oracle
su -l oracle;

# 查看oracle的端口监听是否启动。用于【远程连接】。默认端口号:1521
lsnrctl status;

# 启动监听。注意一定要在oracle用户下执行
# 注意默认它不是开机自启动的,所以虚拟机重启后,需要手动启动监听
lsnrctl start;

# 停止监听
lsnrctl stop;

# 使用sqlplus工具连接oracle
# 使用系统用户校验登录。以用户sys登录
sqlplus / as sysdba;
# 等价于
sqlplus sys/密码 as sysdba;

# 使用sqlplus工具连接远程的oracle。以sys用户为例
sqlplus sys/密码@主机ip:1521/实例名 as sysdba;

# 连接oracle之后,注意要启动默认实例!!!如果当前默认实例没启动,是没办法操作数据库的。
startup;

# 默认会有一个锁定的scott用户,给scott用户解锁
alter user scott accout unlock;
# scott的默认密码为:tiger。给它更改密码
alter user scott identified by 新密码;


# 查看当前登录用户
show user;

# 查看当前所有的数据库。需要dba权限的帐号,如sys,system
select * from v$database;
select name from v$database;

# 查看当前实例
select * from v$instance;

# 查看数据库的所有用户
select * from dba_users;
select username, password from dba_users;

# 查看所有用户的所有表
select * from all_tables;
# 查看当前登录用户的所有表
select * from user_tables; 
# 查看某个指定用户的所有表。
select * from all_tables where OWNER='大写的用户名'; 

Set Oracle to start automatically

1. Confirm the environment variable ORACLE_HOME 

# 切换成oracle用户
# 查看ORACLE_HOME。注意在root用户下是无法查看的
echo $ORACLE_HOME

2. Modify the startup script dbstart

vim $ORACLE_HOME/bin/dbstart

Then change ORACLE_HOME_LISTNER=$1 to ORACLE_HOME_LISTNER=$ORACLE_HOME

3. Modify the /etc/oratab file

The /etc/oratab file is automatically created when dbca builds the database

vim /etc/oratab

Modify the following figure 

4. Edit the /etc/rc.d/rc.local startup file and add it to the end

su oracle -lc /data/oracle/product/11.2.0/bin/dbstart

5. Grant rc.loacl execution permissions

chmod 755 /etc/rc.d/rc.local

6. Restart the test, slightly

Connect to Oracle with Navicat

In the above, we use the sqlplus tool to connect to oracle. But we found two extremely unfriendly places:

1. Generally speaking, oracle comes with the sqlplus tool. But if we connect to the oracle on the remote server, the machine naturally does not have the sqlplus tool. Of course, you can also connect to the remote host through xshell and other tools, and directly operate the remote host to connect to oracle. Or use the full version of the client provided by Oracle, but the experience is not as good as Navicat.

2. After all, you are operating in the terminal, and inputting commands is more troublesome. For data that exceeds the width of the screen buffer, such as a table with a larger output width, it will be extremely unsightly due to forced line breaks. As shown below:

1. Install Navicat 

Navicat is powerful and can solve the above two problems. Here I recommend a cracked version of Navicat 15 :

https://www.cnblogs.com/kkdaj/p/12794804.html

2. Set up the oci environment for Navicat

Note: Be sure to download the corresponding version of the oci file from the official website! ! !

64位windows的oci:https://www.oracle.com/database/technologies/instant-client/winx64-64-downloads.html

I am using Oracle version 11.2.0.1.0 . You will find that this version of the simplified client cannot be found in the above connection, then download the following version. After setting the oci path in Navicat, restart Navicat! ! !

3. New connection

Before connecting, be sure to:

(1) Open oracle port monitoring

(2) Start the default instance of oracle

 

Guess you like

Origin blog.csdn.net/qq_43290318/article/details/108812903