DEV Community

Pheak Pheasa
Pheak Pheasa

Posted on

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.

Postgres on Neon - Get the Free Plan

No credit card required. The database you love, on a serverless platform designed to help you build faster.

Get Postgres on Neon

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay