會員註冊 / 登入  |  電腦版  |  Jump to bottom of page

PostgreSQL » PostgreSQL同時開新帳號及資料庫的方法

發表人: andowson, 七段學員
2007-11-09 09:40:58
將下面的程式儲存為/var/lib/pgsql/createdb.sh

psql -c "create user $1 createdb;" template1
psql -c "create database $1 with encoding 'unicode';" -U $1 template1
psql -c "alter user $1 nocreatedb;" template1
psql -c "alter user $1 with encrypted password '$1';" template1

然後將createdb.sh設定為可執行
chmod 755 createdb.sh

後續要新增資料庫執行下面的指令即可
su - postgres

./createdb.sh dbname

會產生名稱為dbname的使用者,密碼也是dbname,而資料庫名稱也是dbname




會員註冊 / 登入  |  電腦版  |  Jump to top of page