Postgres(Linux)

(0) postgresユーザにパスワード設定 passwd postgres (0.1) Postgresql起動   # service postgresql start (0.2) DB初期化    # service postgresql initdb (1) データベースのユーザを作成する [root@localhost root]# su postgres bash-2.05b$ createuser Enter name of user to add: user_name Shall the new user be allowed to create databases? (y/n) y Shall the new user be allowed to create more new users? (y/n) y CREATE USER (2) データベースを作成する bash-2.05b$ createdb db_user_name CREATE DATABASE (3) フロントエンドアプリケーション(psql)の起動 bash-2.05b$ psql db_user_name Welcome to psql 7.3.2, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit db_user_name=# (4) psqlでの確認 db_user_name=# \l List of databases Name | Owner | Encoding -----------+----------+----------- db_user_name | postgres | SQL_ASCII template0 | postgres | SQL_ASCII template1 | postgres | SQL_ASCII (3 rows) (5) ユーザ名で、テーブルの作成 db_user_name=# \q bash-2.05b$ su user_name Password: [user_name@localhost root]$ psql db_user_name Welcome to psql 7.3.2, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit db_user_name=# create table addr( db_user_name(# id varchar(8) not null, db_user_name(# name varchar(32) not null, db_user_name(# mail varchar(64) , db_user_name(# primary key(id) db_user_name(# ); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'addr_pkey' for table 'addr' CREATE TABLE db_user_name=# \dt List of relations Schema | Name | Type | Owner --------+------+-------+------- public | addr | table | user_name (1 row) db_user_name=# \d addr Table "public.addr" Column | Type | Modifiers --------+-----------------------+----------- id | character varying(8) | not null name | character varying(32) | not null mail | character varying(64) | Indexes: addr_pkey primary key btree (id) db_user_name=# select * from addr; id | name | mail ----+------+------ (0 rows) db_user_name=# insert into addr(id,name,mail) values ('1','owner','office@sen-it.net'); INSERT 16982 1 db_user_name=# select * from addr; id | name | mail ----+-------+------------------- 1 | owner | office@sen-it.net (1 row) db_user_name=# \d List of relations Schema | Name | Type | Owner --------+------+-------+------- public | addr | table | user_name (1 row) db_user_name=# \q [user_name@localhost root]$ [user_name@localhost root]$ su Password: ユーザ権限の設定   GRANT 権限 ON table名 TO ユーザ名;    権限は、all,select,insert,update等 ユーザ権限の削除   REVOKE 権限 ON table名 FROM ユーザ名;    権限は、all,select,insert,update等 ユーザ権限の確認   \z

phpPgAdmin

[ホームページに戻る]  [Linux(Feodra)に戻る]