ubuntu server create database and create new user with password for there database in postgresql.

pheak_pheasa

Pheak Pheasa

Posted on April 3, 2024

ubuntu server create database and create new user with password for there database in postgresql.

To create a new database and a new user with a password in PostgreSQL on Ubuntu Server, you can follow these steps:

  1. Install PostgreSQL if it's not already installed:
sudo apt update
sudo apt install postgresql postgresql-contrib
  1. Switch to the postgres user:
sudo -i -u postgres
  1. Access the PostgreSQL prompt:
psql
  1. Create a new database:
CREATE DATABASE mydatabase;
  1. Create a new user and set a password:
CREATE USER myuser WITH PASSWORD 'mypassword';

Replace myuser with your desired username and mypassword with your desired password.

  1. Grant privileges on the database to the user:
GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser;
  1. Exit the PostgreSQL prompt:
\q
  1. Exit from the postgres user:
exit

That's it! You've now created a new database and a new user with a password in PostgreSQL on your Ubuntu Server.

💖 💪 🙅 🚩
pheak_pheasa
Pheak Pheasa

Posted on April 3, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related