Nruab PostgreSQL rau ntawm Ubuntu

Pin
Send
Share
Send

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.

  1. 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.
  2. 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 chawsudo 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.
  3. Sau tus password rau koj tus lej.
  4. Tom qab siv ntawdwget -q //www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-yawm sij ntxiv -kom ntxiv pob khoom.
  5. Nws tshua tsuas yog hloov kho lub kaw lus system nrog tus qauv hais kom uasudo apt-tau hloov tshiab.
  6. 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 consolesudo apt-tau nruab postgresql postgresql-contribthiab 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:

  1. Sau hais kom uasudo su - postgresthiab 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.
  2. Nkag mus rau hauv lub chaw tswj hwm nyob rau hauv cov lus qhia ntawm cov profile sivpsqlCov. 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.
  3. Saib cov ntaub ntawv hais txog kev sib tham PostgreSQL tam sim no dhau ntawm conninfo.
  4. 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.

  1. Nyob hauv lub console nyob rau hauv kev tswj hwm profile postgres (pab neeg thajsudo 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.
  2. 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.
  3. 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 txibtsim muaj lumpicsqhov twg pob leeg - Lub npe username.
  4. Qhov kev hloov pauv mus ua haujlwm nrog daim ntawv sau tseg tau tshwm sim dhau lospsql -d lumpicsqhov 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:

  1. 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.

  2. Tom qab nkag mus, nws tsuas yog tso saib lub rooj ntawm lub vijtsam nrog d.
  3. Koj pom qhov project yooj yim uas tseem tsis tau muaj cov ntaub ntawv.
  4. Cov ntaub ntawv tshiab yog ntxiv los ntawm kev hais kom uaINSERT 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.
  5. 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');
  6. Khiav lub rooj dhauXAIV * 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.
  7. Yog tias koj xav rho tawm tus nqi, ua nws dhau cov lus txibRHO 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.

  1. Feem ntau los ntawm "Chaw Nres Tsheb" Rub tawm cov tsev qiv ntawv ntawv tshiab dhau lossudo apt-tau hloov tshiab.
  2. Nruab Nruab Apache Web Serversudo apt-mus nruab apache2.
  3. Tom qab kev teeb tsa, kuaj nws cov kev ua tau zoo thiab kev siv syntaxsudo apache2ctl configtestCov. 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.
  4. Pib lub server los ntaus ntawvsudo systemctl pib apache2.
  5. 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 khoomsudo Apt nruab phppgadmin.
  6. 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 ntsuasgedit /etc/apache2/conf-available/phppgadmin.confCov. Yog tias daim ntawv nyeem ntawv nkaus xwb, koj yuav xav tau cov lus txib ua ntej gedit qhia kujsudo.
  7. 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 yamCov. 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.
  8. Rov pib qhov web serverkev pab sudo apache2 rov pib duathiab 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

Pin
Send
Share
Send