Installing Oracle Database on MacOS Using Docker
Introduction
Docker is a powerful tool for creating and managing containerized applications. Among its many uses, it provides an easy way to set up and run databases, such as Oracle, on your local machine, regardless of your operating system. In this article, we will guide you on how to install Oracle database on MacOS using Docker.
Prerequisites
Before we start, please make sure you have Docker installed on your MacOS. If you haven't, you can download it from the official Docker website.
Step 1: Pull the Oracle Docker Image
To get started, open the Terminal on your Mac and pull the Oracle database image from the Docker Hub. You can do this by running the following command:
docker pull deepdiver/docker-oracle-xe-11g
Step 2: Create an Oracle Docker Container
After pulling the Oracle Docker image, the next step is to create a Docker container. Run the following command in the Terminal:
docker run -d -p 1521:1521 --name oracle11g deepdiver/docker-oracle-xe-11g
Step 3: Access the Oracle Docker Container
To interact with your Oracle database, you'll need to access the Docker container. You can do this by running the following command:
# 通过 docker ps -a 获取 container id
docker ps -a
docker exec -it <container id> /bin/bash
This will open a shell in container.
Step 4: Connect to Oracle Database
First, you should connect to the Oracle Database with the following command:
sqlplus system/oracle
This will log you in as the 'system' user, with 'oracle' as the password.
Next, you'll want to create a new user. You can start by viewing all existing users with the following command:
# Use SELECT to view all current users
select username,password from dba_users;
This SQL command will return a list of all users and their associated passwords.
After checking existing users, you can proceed to create a new user with the following command:
# Create a new user with the following command
# create user <username> identified by <password>
create user peter identified by 123456;
This will create a new user named "peter" with the password "123456".
Finally, to grant all privileges to your newly created user, use the following command. Remember that the username must be in uppercase:
grant all privileges to PETER;
With these steps, you have created a new user "peter" with the password "123456", and granted all privileges to this user.
Conclusion
With these simple steps, you have set up an Oracle database on your MacOS using Docker. It offers the flexibility and the convenience of running the Oracle database inside a containerized environment, saving you the complex process of installing Oracle directly on your MacOS. Remember to replace the placeholder in the commands and desired user credentials for a successful setup.
- 0
- 0
-
分享