Database


Databases installed in Oracle Cloud are MariaDB, PostgreSQL and MongoDB. MariaDB is activate, but PostgreSQL and MongoDB are inactivate currently. The process of installation is followings.

MariaDB

sudo apt update
sudo apt install mariadb-server mariadb-client
sudo mariadb-secure-installation
Switch to unix_socket authentication [Y/n] n
 ... skipping.

Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

Remove anonymous users? [Y/n]
 ... Success!

Disallow root login remotely? [Y/n]
 ... Success!

Remove test database and access to it? [Y/n]
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reload privilege tables now? [Y/n]
 ... Success!
sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf
------------------
[mysqld]
------------------
[mysqld]
port           = 11010
------------------

------------------
bind-address            = 127.0.0.1
------------------
# bind-address            = 127.0.0.1
bind-address            = 0.0.0.0
------------------
sudo systemctl enable mariadb
sudo systemctl restart mariadb

sudo netstat -tulpn

According to Switch to unix_socket authentication [Y/n]
sudo mariadb
sudo mariadb -u root -p
mariadb -u root -p
use mysql;
CREATE DATABASE databasename;
SHOW DATABASES;
DROP DATABASE databasename;

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
CREATE USER 'username'@'%' IDENTIFIED BY 'password';

SELECT host, user, password FROM user;

DROP USER 'username'@'localhost';
DROP USER 'username'@'%';

GRANT ALL PRIVILEGES ON databasename.* TO 'username'@'localhost';
GRANT ALL PRIVILEGES ON databasename.* TO 'username'@'%';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%';

FLUSH PRIVILEGES;

PostgreSQL

sudo apt update
sudo apt install postgresql postgresql-contrib

sudo -i -u postgres
psql
CREATE USER usename PASSWORD 'password' superuser;
\du

CREATE DATABASE databasename OWNER username;
\l

\q
sudo vi /etc/postgresql/14/main/pg_hba.conf
------------------
# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
------------------
# "local" is for Unix domain socket connections only
# local   all             all                                     peer
local   all             all                                     md5
# IPv4 local connections:
# host    all             all             127.0.0.1/32            scram-sha-256
host    all             all             0.0.0.0/0            scram-sha-256
------------------
sudo vi /etc/postgresql/14/main/postgresql.conf
------------------
#listen_addresses = 'localhost'         # what IP address(es) to listen on;
------------------
#listen_addresses = 'localhost'         # what IP address(es) to listen on;
listen_addresses = '*'                  # what IP address(es) to listen on;
------------------

------------------
port = 5432                           # (change requires restart)
------------------
# port = 5432                         # (change requires restart)
port = 11011                          # (change requires restart)
------------------
sudo systemctl enable postgresql
sudo systemctl restart postgresql

psql -U username -d databasename

MongoDB

wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/mongodb.gpg
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt update
sudo apt install -y mongodb-org

sudo vi /etc/mongod.conf
# network interfaces
------------------
net:
  port: 27017
  bindIp: 127.0.0.1
------------------
net:
#  port: 27017
#  bindIp: 127.0.0.1
  port: 11012
  bindIp: 0.0.0.0
------------------

------------------
#security:
------------------
security:
  authorization: 'enabled'
------------------
sudo systemctl enable mongod
sudo systemctl restart mongod

mongosh --port 11012
use admin

db.createUser({ 
    user: 'username',
    pwd: 'password',
    roles: ['root']
});
mongosh --port 11012 -u username

Leave a Reply

Your email address will not be published. Required fields are marked *