PostgreSQL yog qhov kev tswj hwm ntaub ntawv pub dawb siv rau ntau lub platform, suav nrog Windows thiab Linux. Cov cuab yeej txhawb nqa ntau ntawm cov hom ntaub ntawv, muaj cov lus sau ua tau thiab txhawb nqa kev siv hom lus ntawm lub cajmeem qub. Nyob rau hauv Ubuntu, PostgreSQL yog nruab los ntawm "Chaw Nres Tsheb" siv cov chaw sau cov nom lossis cov neeg siv, thiab tom qab ntawd, npaj ua haujlwm, kuaj thiab tsim cov ntxhuav tau nqa tawm.
Nruab PostgreSQL hauv Ubuntu
Cov ntaub ntawv siv rau hauv ntau qhov chaw, tab sis kev tswj hwm kev tswj hwm tau xis. Ntau tus neeg siv nres ntawm PostgreSQL, nruab nws rau ntawm lawv OS thiab pib ua haujlwm nrog cov ntxhuav. Tom ntej no, peb xav ua ntu zus los piav qhia txhua tus txheej txheem kev teeb tsa, thawj qhov kev teeb tsa thiab kev teeb tsa ntawm lub cuab yeej tau hais tseg.
Kauj ruam 1: Nruab PostgreSQL
Tau kawg, koj yuav tsum pib los ntawm kev ntxiv txhua cov ntaub ntawv tsim nyog thiab cov tsev qiv ntawv rau Ubuntu kom paub meej tias txoj haujlwm ua haujlwm ntawm PostgreSQL. Qhov no yog ua tiav siv lub console thiab tus neeg siv lossis cov neeg siv khoom nom tswv.
- Khiav "Chaw Nres Tsheb" txhua txoj hauv kev yooj yim, piv txwv li, los ntawm cov ntawv qhia zaub mov lossis los ntawm nias tus sib xyaw tseem ceeb Ctrl + kev + T.
- Ua ntej, peb nco ntsoov cov neeg siv khoom lag luam, vim tias cov kho tshiab tawm tshiab feem ntau upload tawm ua ntej. Muab cov lo lus txib tso rau hauv qhov chaw
sudo sh -c 'echo "deb //apt.postgresql.org/pub/repos/apt/' lsb_release -cs'-pgdg lub ntsiab" >> /etc/apt/sources.list.d/pgdg.list '
thiab nyem Sau. - Sau tus password rau koj tus lej.
- Tom qab siv ntawd
wget -q //www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-yawm sij ntxiv -
kom ntxiv pob khoom. - Nws tshua tsuas yog hloov kho lub kaw lus system nrog tus qauv hais kom ua
sudo apt-tau hloov tshiab
. - Yog tias koj txaus siab xav tau qhov tam sim no muaj nyob ntawm PostgreSQL los ntawm cov chaw raug cai, koj yuav tsum sau rau hauv lub console
sudo apt-tau nruab postgresql postgresql-contrib
thiab paub meej tias qhov sib ntxiv ntawm cov ntaub ntawv.
Tom qab ua tiav ntawm kev teeb tsa tiav, koj tuaj yeem npaj mus rau hauv tus txheej txheem account, kos lub system thiab pib teeb tsa.
Kauj ruam 2: Pib PostgreSQL thawj zaug
Kev tswj cov ntsia DBMS kuj tshwm sim dhau los "Chaw Nres Tsheb" siv cov lus txib tsim nyog. Hu rau tus neeg siv tsim los ntawm lub neej ntawd zoo li qhov no:
- Sau hais kom ua
sudo su - postgres
thiab nyem rau ntawm SauCov. Qhov kev nqis tes ua no yuav ua rau koj hloov mus rau kev tswj hwm sawv cev ntawm tus lej qub ntawm tus account, uas tam sim no ua qhov tseem ceeb. - Nkag mus rau hauv lub chaw tswj hwm nyob rau hauv cov lus qhia ntawm cov profile siv
psql
Cov. Kev ua kom zoo yuav pab koj tawm tsam ib puag ncig.pab
- nws yuav pom tag nrho cov lus txib thiab kev sib cav. - Saib cov ntaub ntawv hais txog kev sib tham PostgreSQL tam sim no dhau ntawm
conninfo
. - Tawm hauv qhov chaw ib puag ncig yuav pab tau pab neeg
q
.
Tam sim no koj paub tias yuav nkag mus rau hauv koj tus lej li cas thiab mus rau ntawm lub chaw tswj hwm, yog li nws yog lub sijhawm tau nce mus rau tsim tus neeg siv tshiab thiab nws lub hauv paus.
Kauj ruam 3: Tsim Tus Neeg Siv thiab Ntaub Ntawv
Nws tsis yog ib qho yooj yim los mus ua haujlwm nrog tus account uas twb muaj lawm, thiab nws tsis yog qhov tsim nyog tas li. Tias yog vim li cas peb qhia tawm los xav txog cov txheej txheem rau kev tsim daim ntawv tshiab thiab txuas cov ntaub ntawv sib txawv rau nws.
- Nyob hauv lub console nyob rau hauv kev tswj hwm profile postgres (pab neeg thaj
sudo su - postgres
) sautus tsim - sab hauv
, thiab tom qab ntawd muab nws lub npe tsim nyog los ntawm sau cov cim hauv kab uas tsim nyog. - Tom ntej no, txiav txim siab seb koj puas xav tso cai rau tus neeg siv superuser cov cai los mus saib tag nrho cov khoom siv hauv system. Tsuas xaiv cov kev xaiv tsim nyog thiab npaj mus.
- Nws yog qhov zoo dua yog hu rau lub hauv paus ntawm lub npe tib lub npe raws li tus lej tau muab npe, yog li koj yuav tsum siv cov lus txib
tsim muaj lumpics
qhov twg pob leeg - Lub npe username. - Qhov kev hloov pauv mus ua haujlwm nrog daim ntawv sau tseg tau tshwm sim dhau los
psql -d lumpics
qhov twg pob leeg - lub npe ntawm cov ntaub ntawv.
Kauj Ruam 4: Tsim Lub Rooj thiab Ua Haujlwm nrog Cov Kab
Nws yog lub sijhawm los tsim koj thawj lub rooj hauv qhov chaw tsim khoom. Qhov txheej txheem no tseem tau ua dhau ntawm lub console, txawm li cas los xij, nws yuav tsis nyuaj rau kam nrog cov kev cai tseem ceeb, vim tias koj tsuas xav tau cov hauv qab no:
- Tom qab koj mus rau lub chaw khaws ntaub ntawv, sau cov cai hauv qab no:
TSIM NYOG ROOJ KUAJ (
equip_id serial THAWJ UA LUAJ,
yam varchar (50) TSIS PUB,
xim varchar (25) TSIS PUB,
qhov chaw sib txawv (25) kos (qhov chaw nyob hauv ('sab qaum teb', 'sab qab teb', 'sab hnub poob', 'sab hnub tuaj', 'sab qaum teb', 'sab qab teb', 'qab teb', 'sab qaum teb')),
install_date hnub tim
);Rooj lub npe ua ntej xeem ntawv (koj tuaj yeem xaiv lwm lub npe). Txhua kem tau piav qhia hauv qab no. Peb tau xaiv cov npe hom varchar thiab xim sib txawv tsuas yog ua piv txwv, koj tuaj yeem nkag mus qhov taw qhia ntawm lwm qhov, tab sis tsuas yog siv cov ntawv Latin. Cov naj npawb hauv cov ntawv sib txuas ua lub luag haujlwm rau qhov loj ntawm kem, uas yog ncaj qha rau cov ntaub ntawv tso rau ntawd.
- Tom qab nkag mus, nws tsuas yog tso saib lub rooj ntawm lub vijtsam nrog
d
. - Koj pom qhov project yooj yim uas tseem tsis tau muaj cov ntaub ntawv.
- Cov ntaub ntawv tshiab yog ntxiv los ntawm kev hais kom ua
INSERT INTO test (hom, xim, qhov chaw, install_date) VALUES ('swb', 'xiav', 'sab qab teb', '2018-02-24');
Lub npe ntawm lub rooj yog qhia ua ntej, hauv peb rooj plaub nws yog xeem ntawv, tom qab ntawd txhua kab qhia tau teev, thiab qhov muaj nuj nqis muaj qhia hauv kab thaiv, ib txwm nyob rau hauv kab ntawv cim. - Tom qab ntawd koj tuaj yeem ntxiv lwm txoj kab, piv txwv li,
INSERT INTO test (hom, xim, qhov chaw, install_date) VALUES ('viav vias', 'daj', 'sab qaum teb', '2018-02-24');
- Khiav lub rooj dhau
XAIV * LOS xeem;
txhawm rau soj ntsuam qhov tshwm sim. Raws li koj tuaj yeem pom, txhua yam nyob rau qhov raug thiab cov ntaub ntawv nkag mus raug. - Yog tias koj xav rho tawm tus nqi, ua nws dhau cov lus txib
RHO TAWM LOS UA KE TWG yam = 'swb';
los ntawm suav qhov xav tau nyob rau hauv nqe lus cim.
Kauj Ruam 5: Nruab phpPgAdmin
Nws tsis yog ib qho yooj yim los tswj cov ntaub ntawv los ntawm lub console, yog li nws yog qhov zoo tshaj plaws los hloov kho nws los ntawm txhim kho phpPgAdmin GUI tshwj xeeb.
- Feem ntau los ntawm "Chaw Nres Tsheb" Rub tawm cov tsev qiv ntawv ntawv tshiab dhau los
sudo apt-tau hloov tshiab
. - Nruab Nruab Apache Web Server
sudo apt-mus nruab apache2
. - Tom qab kev teeb tsa, kuaj nws cov kev ua tau zoo thiab kev siv syntax
sudo apache2ctl configtest
Cov. Yog tias muaj qee yam ua tsis ncaj ncees lawm, nrhiav qhov yuam kev hauv qhov kev piav qhia ntawm lub vas sab Apache lub vev xaib. - Pib lub server los ntaus ntawv
sudo systemctl pib apache2
. - Tam sim no tias tus neeg rau zaub mov ua haujlwm tau zoo, koj tuaj yeem ntxiv cov phpPgAdmin qiv los ntawm rub tawm ntawm cov ntaub ntawv los ntawm lub chaw cia khoom
sudo Apt nruab phppgadmin
. - Tom ntej no, koj yuav tsum tau hloov kho me ntsis ntawm cov ntaub ntawv teeb tsa. Qhib nws hla phau ntawv sau los ntawm kev ntsuas
gedit /etc/apache2/conf-available/phppgadmin.conf
Cov. Yog tias daim ntawv nyeem ntawv nkaus xwb, koj yuav xav tau cov lus txib ua ntej gedit qhia kujsudo
. - Ua ntej ntawm kab "Yuav tsum tau hauv zos" tso
#
kom nws hloov mus ua ib tug saib, thiab los ntawm hauv qab nkag musCia los ntawm txhua yam
Cov. Tam sim no nkag mus rau qhov chaw nyob yuav qhib rau tag nrho cov khoom siv hauv lub network, thiab tsis yog rau lub PC hauv zos. - Rov pib qhov web server
kev pab sudo apache2 rov pib dua
thiab koj tuaj yeem ruaj ntseg mus ua haujlwm nrog PostgreSQL.
Hauv tsab xov xwm no, peb tau soj ntsuam tsis yog PostgreSQL nkaus xwb, tab sis kuj tau teeb tsa ntawm Apache web server, uas yog siv hauv kev sib txuas ntawm cov software LAMP. Yog tias koj xav paub meej txog kev ua haujlwm tag nrho ntawm koj cov xaib thiab lwm cov haujlwm, peb xav kom koj paub koj tus kheej nrog cov txheej txheem ntawm kev ntxiv lwm cov khoom siv los ntawm kev nyeem peb lwm tsab xov xwm ntawm qhov txuas hauv qab no.
Saib ntxiv mus: Txhim kho lub LAMP Software Suite ntawm Ubuntu