最近因?yàn)橛?/span>HYPERIC產(chǎn)品,裝了一下Postgres數(shù)據(jù)庫,下面簡(jiǎn)說下在WINDOWS下安裝的情況。
下載那個(gè)直接解壓版,解壓
在"$PG"目錄下創(chuàng)建一個(gè)rootpass.txt文件,內(nèi)容為數(shù)據(jù)庫的超級(jí)用戶密碼。可以填個(gè)“p”,方便后面登陸。
準(zhǔn)備工作到此結(jié)束,下面的步驟以管理員身份執(zhí)行。
移動(dòng)DLL文件[8.1.5及以上版本不需要這一步驟]:
cd $PG
move /y lib\comerr32.dll bin\
move /y lib\krb5_32.dll bin\
move /y lib\libeay32.dll bin\
move /y lib\libiconv-2.dll bin\
move /y lib\libintl-2.dll bin\
move /y lib\libpq.dll bin\
move /y lib\pthreadGC2.dll bin\
move /y lib\ssleay32.dll bin\
添加新的postgres用戶,并將密碼設(shè)為:p
net user postgres p /ADD /EXPIRES:NEVER /PASSWORDCHG:NO
net localgroup users postgres /delete
創(chuàng)建data目錄并設(shè)置訪問權(quán)限:
md data
cacls . /T /E /P postgres:R
cacls data /T /E /P postgres:C
POSTGRES不支持管理員狀態(tài)運(yùn)行,我們用RUNAS來做,如果失敗,可以查下是不是有個(gè)SECOND LOGON服務(wù)是不是停了,啟動(dòng)一下即可。
初始化PostgreSQL數(shù)據(jù)庫,切換用戶時(shí)需要手動(dòng)輸入postgres用戶的密碼:p
runas /noprofile /env /user:postgres "bin\initdb -D data -E EUC_CN --locale=\"Chinese_People's Republic of China.936\" -A md5 -U postgres --pwfile=rootpass.txt"
這樣就安裝好了。需要說明的是數(shù)據(jù)庫默認(rèn)編碼為:EUC_CN(GB2312),區(qū)域設(shè)置為:zh_CN.GBK,數(shù)據(jù)庫超級(jí)用戶名為:root,密碼為rootpass.txt文件內(nèi)容,使用md5認(rèn)證。
以后可以使用:
runas /noprofile /env /user:postgres "bin\pg_ctl start -w -D data"
啟動(dòng)PG,使用:
runas /noprofile /env /user:postgres "bin\pg_ctl stop -D data -m smart"
關(guān)閉PG。
用登錄:
runas /noprofile /env /user:postgres "bin\psql -U postgres"
登錄后就可以創(chuàng)用戶,創(chuàng)數(shù)據(jù)庫。
一些命令對(duì)比:
PostgreSQL與MySQL命令比較
|
PostgreSQL
|
MySQL
|
服務(wù)啟動(dòng): 1)#service postgresql start 2)#/etc/init.d/postgresql start 3)#su – postgresql $pg_ctl start PostgreSQL的進(jìn)程號(hào):1210、1207、
|
服務(wù)啟動(dòng): 1)#service mysqld start 2)#/etc/init.d/mysqld start 3)#safe_mysqld&
MySQL的進(jìn)程號(hào)為1663
|
第一次進(jìn)入數(shù)據(jù)庫: #su – postgres $createdb (建名為postgres的數(shù)據(jù)庫) $psql
|
第一次進(jìn)入數(shù)據(jù)庫:
#mysql mysql> (出現(xiàn)這個(gè)提示符說明成功)
|
創(chuàng)建用戶:(用戶Ajian,密碼:123) #su – postgres
$psql
=#create user ajian with password ‘123’
|
創(chuàng)建用戶:(用戶Ajian,密碼:123) #grant all privileges on *.* to ajian@"%" identified by "123"
(注意:同還可以分配權(quán)限,這里是ALL)
|
創(chuàng)建數(shù)據(jù)庫(My):
#su – postgres
$psql
=#create database My with owner = ajian template = template1 encoding=’UNICODE’;
|
創(chuàng)建數(shù)據(jù)庫(My):
1)#mysql
Mysql>create database My;
2)#mysqladmin create My
|
查看用戶和數(shù)據(jù)庫:
#su – postgres
$psql
=#\l (查看數(shù)據(jù)庫) =#\du (查看用戶)
|
查看用戶和數(shù)據(jù)庫:
1)#mysql
Mysql>show databases; (看數(shù)據(jù)庫)
2)#mysqlshow
|
新建用戶登錄:
(首先修改配置文件)
# vi /var/lib/pgsql/data/pg_hba.conf(在最后加)
host all all 127.0.0.1 255.255.255.255 md5
再重啟服務(wù):#service postgresql restart
登錄:#psql –h 127.0.0.1 –U ajian My
Password:
|
新建用戶登錄:
1)#mysql –u ajian –p (帶口令登錄)
2)#mysql
Mysql>use My;
(不帶口令登錄一般用于本機(jī))
|
創(chuàng)建表(employee):
=#create table employee(
(#employee_id int primary key,
(#name char(8),
(#sex char(2));
|
創(chuàng)建表:
>create table employee(
->employee_id int primary key,
->name char(8),
->sex char(2));
|
查看表:
=#\dt
|
查看表:
>show tables;
|
查看表的結(jié)構(gòu):
=#\d employee
|
查看表的結(jié)構(gòu):
>sescribe employee;
|
向表中添加數(shù)據(jù):
=#insert into employee values
-#(‘1’,’zhang’,’F’);
-#(‘2’,’chen’,’M’,);
|
向表中添加數(shù)據(jù):
>insert into employee values
->(‘1’,’zhang’,’F’);
->(‘2’,’chen’,’M’,);
|
查看表的數(shù)據(jù):
=#select * from emlpoyee
|
查看表的數(shù)據(jù):
>select * from emlpoyee;
|
創(chuàng)建索引(IN_employee):
=#create index IN_employee on employee(name);
查看索引:
=#\di
刪除索引:
=#drop index IN_employee on employee;
重建索引:
=#reindex table employee;(重建employee所有的)
=#reindex index IN_employee;(重建指定的)
|
創(chuàng)建索引(IN_employee):
1)>create index IN_employee on employee(name);
2)>alter table employee add index IN_employee(name);
查看索引:
>show index from employee;
刪除索引:
1)>drop index IN_employee on employee;
2)>alter table emlpoyee drop index IN_employee;
|
刪除表:
=#drop table employee;
|
刪除表:
>drop table employee;
|
刪除數(shù)據(jù)庫:(注意命令前面的標(biāo)志)
1)=#drop database ajian;
2)$dropdb ajian
|
刪除數(shù)據(jù)庫:(注意命令前面的標(biāo)志)
1)>drop database ajian;
2)#mysqladmin drop ajian
|
|
|
posted on 2007-08-12 15:56
我愛佳娃 閱讀(5771)
評(píng)論(0) 編輯 收藏 所屬分類:
DB相關(guān)