PostgreSQL yog ib txoj kev pub dawb rau kev tswj ntau yam kev sib txuas lus, tau siv rau ntau lub platforms, suav nrog Windows thiab Linux. Tus cuab yeej txhawb ntau ntau hom ntaub ntawv, muaj cov lus sau ua lus sau thiab txhawb cov haujlwm siv cov lus siv hom lus. Nyob rau hauv Ubuntu, PostgreSQL yog ntsia ntawm "Terminal" siv cov khoom siv los sis cov neeg siv khoom siv, thiab tom qab ntawd qhov kev npaj ua haujlwm, sim thiab tsim cov ntxhuav yog nqa tawm.
Nruab PostgreSQL hauv Ubuntu
Databases yog siv ntau qhov chaw, tab sis txoj kev tswj lub cev zoo rau lawv muaj kev tswj tus kheej. Ntau cov neeg siv ntawm PostgreSQL, nruab rau hauv lawv OS thiab pib ua hauj lwm nrog cov ntxhuav. Tom ntej no, peb xav ua kauj ruam los ntawm kauj ruam piav tag nrho kev txhim kho installation, thawj lub community launch thiab teeb ntawm cov cuab yeej hais.
Kauj ruam 1: Nruab PostgreSQL
Tau kawg, koj yuav tsum pib los ntawm kev ntxiv tag nrho cov ntaub ntawv tsim nyog thiab qiv rau Ubuntu los xyuas kom meej txog kev ua haujlwm ntawm PostgreSQL. Qhov no yog siv cov console thiab cov neeg siv los sis cov neeg tuav haujlwm.
- Khiav mus "Terminal" nyob rau hauv kev yooj yim txoj kev, piv txwv li, los ntawm cov ntawv qhia zaub mov los yog nias lub ntsiab ua ke Ctrl + Alt + T.
- Ua ntej no, peb nco ntsoov cov neeg siv khoom noj khoom haus, vim hais tias feem ntau tsis ntev los no feem ntau tau tshaj tawm thawj zaug. Ntxig rau hauv kev hais kom ua
sudo sh-c 'echo' deb //most.postgresql.org/pub/repos/apt/ 'lsb_release -cs'-pgdg main ">> /etc/apt/sources.list.d/pgdg.list'
thiab ces nias rau Sau. - Sau tus password rau koj tus account.
- Tom qab ntawd siv
wget -q //www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key ntxiv -
ntxiv pob ntawv. - Nws tshua tsuas yog los kho cov tsev qiv ntawv nrog rau cov lus hais ua ke.
sudo apt-tau hloov tshiab
. - Yog hais tias koj xav tau qhov tseeb version muaj PostgreSQL los ntawm tus nom repository, koj yuav tsum sau ntawv hauv console
sudo apt-mus nruab postgresql postgresql-contrib
thiab tshawb xyuas cov ntaub ntawv ntxiv.
Thaum ua tiav ntawm kev txhim kho kev lag luam tiav, koj tuaj yeem pib tsim ib tus as khauj, ntsuas qhov kev khiav hauj lwm ntawm lub system thiab pib kho.
Kauj ruam 2: Pib PostgreSQL Ua Ntej
Kev tswj ntawm DBMS ntsia tau los ntawm "Terminal" siv cov lus txib tsim nyog. Hu rau tus neeg siv lub neej zoo li no:
- Sau cov lus txib
sudo su - postgres
thiab nias rau Sau. Qhov kev nqis tes no yuav tso cai rau koj mus rau kev tswj ntawm tus account uas tau tsim los ntawm lub neej, uas tam sim no yog qhov tseem ceeb tshaj plaws. - Nkag mus rau qhov kev tswj tuav tswj nyob rau hauv lub guise ntawm qhov profile siv los ntawm
psql
. Deal nrog lub chaw yuav pab koj ua kom muaj zogpab
- nws yuav qhia txhua yam muaj cov lus txib thiab cov lus sib tham. - Saib cov ntaub ntawv hais txog qhov kev sib tham ntawm PostgreSQL tam sim no tau ua ntawm
conninfo
. - Tawm ntawm qhov chaw yuav pab tau pab neeg
q
.
Tam sim no koj paub yuav ua li cas nkag tau rau hauv tus account thiab mus rau kev tswj console, yog li nws yog lub sij hawm mus rau kev tsim ib tus neeg siv tshiab thiab nws cov database.
Kauj ruam 3: Tsim Cov Neeg Siv thiab Database
Nws tsis yog ib txwm yooj yim rau kev ua hauj lwm nrog tus account uas twb muaj lawm, thiab nws tsis tas yuav tsum tau. Tias yog vim li cas peb thov kom xav txog tus txheej txheem tsim cov profile tshiab thiab txuas rau nws ib qho database.
- Ua nyob rau hauv lub console nyob rau hauv lub tswj profile postgres (pab neeg
sudo su - postgres
) sau ntawvcreationuser - interactive
thiab tom qab ntawd ces muab ib lub npe zoo los ntawm kev sau cov cim hauv txoj hlua kom haum. - Tom ntej no, txiav txim siab seb koj xav muab tus neeg siv kev cai superuser los saib xyuas txhua qhov kev pabcuam. Tsuas xaiv cov kev xaiv kom tsim nyog thiab mus.
- Lub database zoo dua lub npe hu ua tus account tau npe, yog li koj yuav tsum siv qhov kev hais kom ua
createdb lumpics
qhov twg lumpics - username. - Hloov ua hauj lwm nrog cov teev database uas tshwm sim los ntawm
psql - le lumpics
qhov twg lumpics - lub npe ntawm tus database.
Kauj ruam 4: Tsim lub rooj thiab ua haujlwm nrog cov kab
Nws yog lub sij hawm los tsim koj lub rooj thawj zaug nyob rau hauv qhov kev teev npe cia. Txoj kev ua no kuj tau ua tiav ntawm lub console, tab sis nws yuav tsis yooj yim rau nrog lub ntsiab lus txib, vim tias txhua yam koj yuav tsum ua yog:
- Tom qab koj tsiv mus rau lub database, sau cov cai nram qab no:
CREATE TABLE test (
equip_id ZAJ LIM TSEEM,
hom varchar (50) TSIS thov,
xim varchar (25) TSIS TXHOB,
qhov chaw nyob hauv (25) check (qhov chaw nyob hauv ('north', 'south', 'west', 'east', 'northeast', 'southeast', 'southwest', 'north')),
nruab install_date hnub
);Ua ntej lub npe lub npe yog teev. xeem (koj tuaj yeem xaiv lwm lub npe). Cov nram qab no qhia txhua kem. Peb xaiv lub npe ntaus varchar thiab xim varchar tsuas yog rau ib qho piv txwv, koj tuaj yeem nkag rau lwm yam cim, tab sis tsuas yog siv cov cim Latin xwb. Cov naj npawb ntawm cov khoom khib nyiab yog lub luag hauj lwm rau qhov loj ntawm sab, uas yog ncaj nraim ntsig txog cov ntaub ntawv muaj kev haum xeeb.
- Tom qab nkag mus nws tshua tsuas yog los tso saib lub rooj ntawm qhov screen nrog
d
. - Koj pom ib qhov project yooj yooj yim uas tsis muaj cov ntaub ntawv tau.
- Cov ntaub ntawv tshiab yog ntxiv los ntawm kev hais kom ua
INSERT INTO test (hom, xim, qhov chaw, install_date) VALUES ('swb', 'blue', 'south', '2018-02-24');
Ua ntej, lub npe ntawm lub rooj yog qhia, nyob rau hauv peb cov ntaub ntawv nws yog xeem, ces tag nrho cov kab txhua tus muaj npe, thiab qhov tseem ceeb hauv cov khoom siv tau pom, tas hauv quotes. - Tom qab ntawd koj tuaj yeem tau ntxiv ib kab, piv txwv li,
INSERT INTO test (hom, xim, qhov chaw, install_date) VALUES ('swing', 'yellow', 'northwest', '2018-02-24');
- Khiav lub rooj los ntawm
XAIV * LOS NTAWM xeem;
los mus ntsuam xyuas qhov kev tshwm sim. Raws li koj tau pom, txhua yam yog teem kom raug thiab cov ntaub ntawv nkag ruaj ntseg. - Yog tias koj xav tau kom tshem tawm cov nqi, ua raws li cov lus txib
RAWS LOS NTAWM kev xeem qhov twg qhov twg = 'swb';
los ntawm specifying qhov yuav tsum tau teb nyob rau hauv quotes.
Kauj Ruam 5: Nrawm phpPgAdmin
Database kev tswj tsis yog ib txwm yoojyim ua kom dhau ntawm lub console, yog li nws yog qhov zoo tshaj plaws los hloov nws los ntawm kev txhim kho tshwj xeeb phpPgAdmin GUI.
- Qhov tshwj xeeb dhau los "Terminal" Download tau qhov tseeb tshiab rau cov tsev qiv ntawv ntawm
sudo apt-tau hloov tshiab
. - Nruab Apache Web Server
sudo apt-mus nruab apache2
. - Tom qab kev txhim kho, sim nws qhov kev ua tau zoo thiab kev siv qhov tseeb ntawm syntax
sudo apache2ctl configtest
. Yog hais tias muaj ib yam dab tsi mus lawm, nrhiav kom tau ib qho yuam kev raws li qhov kev piav qhia nyob rau hauv Apache lub website. - Pib cov neeg rau zaub mov los ntawm sau ntawv
sudo systemctl pib apache2
. - Tam sim no hais tias tus neeg ua hauj lwm lub lag luam tau raug lees paub, koj tuaj yeem ntxiv phpPgAdmin cov tsev qiv ntawv los ntawm kev rub tawm lawv los ntawm tus nom repository ntawm
sudo apt nruab phppgadmin
. - Tom ntej, koj yuav tsum me ntsis hloov cov ntaub ntawv configuration. Qhib nws los ntawm tus qauv phau ntawv, specifying
gedit /etc/apache2/conf-available/phppgadmin.conf
. Yog tias daim ntawv nyeem-nkaus xwb, koj yuav tsum tau hais kom ua ntej gedit qhia kom meejsudo
. - Ua ntej kab "Xav tau lub zos" muab tso rau
#
, kom muab nws rov qab los saib dua, thiab sau hauv qab noCia Ntawm Tag nrho
. Tam sim no nkag mus rau qhov chaw nyob yuav qhib rau tag nrho cov khoom siv nyob rau hauv lub network, thiab tsis yog rau lub zos PC. - Rov qab qhib qhov web server
sudo pab apache2 Updated 10/22/07 / f.Triplett
thiab xav tias dawb mus ua haujlwm nrog PostgreSQL.
Hauv no tsab xov xwm, peb ntsia tsis yog PostgreSQL, tab sis kuj yog lub installation ntawm Apache web neeg rau zaub mov, uas yog siv los ua ke LAMP software. Yog tias koj xav paub meej txog kev ua haujlwm ntawm koj qhov chaw thiab lwm cov haujlwm, peb qhia rau koj kom koj paub koj tus kheej nrog rau lwm txoj hauv kev los ntawm kev nyeem lwm peb cov tshooj ntawm qhov txuas hauv qab no.
Saib kuj: Txhim kho LAMP suite hauv Ubuntu