psql: FATAL: database "" does not exist 解決步驟

問題描述linux

  username@MaLiJun-Ubuntu:~/private$ psql
  psql: FATAL: database "username" does not existsql

使用默認用戶登錄默認數據庫shell

1 使用默認用戶登錄
  sudo su - postgres 2 進入數據庫(默認)   psql template1(或
template1, postgres


建立用戶組,建立用戶,受權用戶權限
 1 creating role on pgsql with privilege as "superuser"
 2 
 3 CREATE ROLE username superuser;
 4 eg. CREATE ROLE demo superuser;
 5 Then create user
 6 
 7 CREATE USER username; 
 8 eg. CREATE USER demo;
 9 Assign privilege to user
10 
11 GRANT ROOT TO username;
12 And then enable login that user, so you can run e.g.: psql template1, from normal $ terminal:
13 
14 ALTER ROLE username WITH LOGIN;
View Code

 

修改密碼
 

有時候,忘記了postgresql 安裝時默認用戶postgres 的密碼,怎麼辦呢?數據庫

linux shell命令下面輸入: sudo -u postgres psql  (這樣就能夠直接登陸進postgres 了, 而後在裏面能夠進行添加用戶,修改密碼之類的,都不是問題了!!)ide

-----------------------------------------------------------------------------------------------------------------post

修改PostgreSQL數據庫的默認用戶postgres的密碼(注意不是linux系統賬號)
  一、PostgreSQL登陸(使用psql客戶端登陸)
         # sudo -u postgres psql        
         //其中,sudo -u postgres 是使用postgres 用戶登陸的意思
         //PostgreSQL數據默認會建立一個postgres的數據庫用戶做爲數據庫的管理員,密碼是隨機的,因此這裏
         //設定爲'postgres'
  2.修改PostgreSQL登陸密碼:
          postgres=# ALTER USER postgres WITH PASSWORD 'postgres';
         //postgres=#爲PostgreSQL下的命令提示符
  3.退出PostgreSQL psql客戶端
         postgres=# \qspa

   [功能說明]
        PostgreSQL數據默認會建立一個postgres的數據庫用戶做爲數據庫的管理員,密碼是隨機的,我人須要修改成指定的密碼,這裏設定爲’postgres’
相關文章
相關標籤/搜索