Qhov wikiHow no qhia koj yuav tsim cov ntaub ntawv siv MySQL li cas. Txhawm rau tsim cov ntaub ntawv, koj yuav tsum qhib "mysql" kab lus hais kom ua interface thiab nkag mus rau cov lus txib database thaum lub server ua haujlwm.
Kauj ruam
Ntu 1 ntawm 3: Qhib MySQL Command Line
Kauj Ruam 1. Xyuas kom tseeb tias MySQL server txuas nrog
Yog serverMySQL tsis nyob hauv lub network, koj tsis tuaj yeem tsim lub database.
Koj tuaj yeem tshawb xyuas tus neeg rau zaub mov xwm txheej los ntawm kev qhib MySQL Workbench, xaiv server, thiab saib rau "Server Status" qhov taw qhia ntawm "Administration - Server Status" tab
Kauj ruam 2. Luam qhov chaw nyob (txoj hauv kev) ntawm daim nplaub tshev teeb tsa
Qhov chaw nyob yuav nyob ntawm qhov ua haujlwm uas siv (piv txwv li Windows lossis Mac):
- Windows - Luam C:/Program Files/MySQL/MySQL Workbench 8.0 CE/thiab xyuas kom tseeb tias koj hloov lub npe nplaub tshev kawg nrog lub npe MySQL nplaub tshev tam sim no.
- Mac-Luam /usr/local/mysql-8.0.13-osx10.13-x86_64/ thiab xyuas kom tseeb tias koj hloov lub npe nplaub tshev kawg nrog lub npe MySQL tam sim no.
Kauj Ruam 3. Qhib lub khoos phis tawj hais kom ua kab lus
Ntawm lub khoos phis tawj Windows, siv Command Prompt. Lub caij no, Mac cov neeg siv computer tuaj yeem siv Terminal.
Kauj Ruam 4. Hloov qhov nkag mus rau MySQL nruab phau ntawv teev npe
Ntaus cd thiab ntxig rau qhov chaw, muab qhov chaw nyob ntawm daim nplaub tshev teeb tsa, thiab nias Enter. Piv txwv li, ntawm lub khoos phis tawj Windows koj tuaj yeem ntaus cov ntawv hauv qab no:
cd C: / Program Files / MySQL / MySQL Workbench 8.0 CE
Kauj Ruam 5. Qhib MySQL tus ID nkag mus hais kom ua
Piv txwv li, txhawm rau qhib kev nkag mus sai rau lub npe siv "kuv", ntaus cov lus hauv qab no thiab nias Enter qhov tseem ceeb:
mysql -u kuv -p
Kauj Ruam 6. Nkag mus rau tus lej nyiaj
Ntaus koj tus lej MySQL tus lej siv tus password, tom qab ntawd nyem Enter. Koj yuav nkag mus rau hauv tus as khauj thiab daim ntawv thov kab ntawv yuav txuas nrog MySQL cov lus txib.
- Koj tuaj yeem pom "MySQL>" tus cim hauv kab hais kom ua kab ntawv thov qhov rai. Los ntawm theem no, txhua cov lus txib koj nkag mus yuav raug ua tiav ntawm daim ntawv thov MySQL kab lus.
- Nkag siab yuav ua li cas nkag mus rau MySQL cov lus txib. MySQL cov lus txib yuav tsum tau nkag mus siv tus lej (()) tom qab ntu kawg ntawm qhov hais kom ua. Koj tseem tuaj yeem nkag mus rau qhov hais kom ua, ntaus ib semicolon, thiab nias Enter dua.
Ntu 2 ntawm 3: Tsim Cov Ntaub Ntawv
Kauj Ruam 1. Tsim cov ntaub ntawv database
Koj tuaj yeem tsim ib qho los ntawm kev ntaus cov lus txib "tsim database" tsim database, ntxiv lub npe database thiab ntxig ib semicolon, thiab nias Enter. Rau ib lub npe hu ua "Pet Data", piv txwv li, nkag mus rau cov lus txib hauv qab no:
tsim cov ntaub ntawv ntawm Pet_Data_Animals;
- Cov npe database tsis tuaj yeem muaj qhov chaw. Yog tias koj xav suav nrog cov chaw hauv koj lub npe, koj yuav tsum siv tus cim qis (piv txwv li "Kuv Tus Phooj Ywg Zoo" los ua "Kuv Tus Phooj Ywg Zoo").
- Txhua qhov MySQL cov lus txib yuav tsum xaus nrog tus lej cim. Yog tias koj tsis nco thawj semicolon, koj tuaj yeem ntaus nws ntxiv rau " …"Yog tso tawm, tom qab ntawv nyem Enter dua.
Kauj Ruam 2. Qhia tam sim no khaws cov ntaub ntawv khaws tseg
Koj tuaj yeem tso tawm cov npe ntawm cov ntaub ntawv khaws tseg los ntawm kev ntaus cov lus txib hauv qab no thiab nias Enter:
qhia databases;
Kauj Ruam 3. Xaiv lub database
Koj tuaj yeem xaiv cov ntaub ntawv khaws tseg los ntawm cov npe los ntawm kev ntaus lub npe siv, nrog "npe" raws li lub npe database. Piv txwv, rau "Cov Ntaub Ntawv Tus Tsiaj" database, ntaus cov lus txib hauv qab no thiab nias Enter:
siv Data_Animal_Pet;
Kauj Ruam 4. Tos kom cov lus pom zoo tshwm tuaj
Thaum koj pom cov kab lus "Database hloov pauv" nyob rau hauv cov lus txib zaum kawg, koj tuaj yeem txav mus rau kev tsim cov ntsiab lus database.
Ntu 3 ntawm 3: Tsim Cov Ntxhuav
Kauj Ruam 1. Nkag siab txog ntau cov lus txib ntawm lub rooj
Muaj ob peb yam tseem ceeb rau cov rooj uas koj yuav tsum paub txog ua ntej tsim lub rooj:
- Title - Cov lus npe tau ntxiv tom qab "tsim cov lus" hais kom ua thiab yuav tsum ua raws li cov cai ib yam li lub npe database (piv txwv li tsis muaj chaw nyob).
- Kab ntawv kab taub hau - Koj tuaj yeem hais qhia kab ntawv kab taub hau los ntawm kev ntaus cov npe hauv npe hauv kab lus (saib piv txwv piv txwv tom ntej).
- Ntev ntev - Thaum hais txog qhov ntev ntawm lub npov, koj tuaj yeem siv "VARCHAR" (tus yam ntxwv sib txawv uas tso cai rau koj ntaus ntawv ntawm ib thiab ntau tus lej "VARCHAR") lossis "CHAR" (yuav tsum tsis muaj ntau dua thiab tsawg dua tus lej tshwj xeeb ntawm tus cim; piv txwv li, "CHAR (1)" xav tau ib tus cim, "CHAR (3)" xav tau peb tus cim, thiab ntxiv rau).
-
Cov Hnub Tim - Yog tias koj xav ntxiv cov hnub rau hauv kab ntawv, siv "DATE" hais kom qhia tias cov kab ntawv yuav tsum tau ua raws li cov hnub. Ib qho ntxiv, cov hnub yuav tsum tau nkag rau hauv hom xyoo-hli-hnub (
XXXX-XX-XX
- ).
Kauj Ruam 2. Qhia lub rooj
Ua ntej nkag mus rau cov ntaub ntawv rau hauv kab ntawv, koj yuav tsum tsim cov qauv ntawm lub rooj los ntawm kev ntaus cov lus txib hauv qab no thiab nias lub pob Enter:
tsim cov npe lub npe (kab lus 1 varchar (20), kab ntawv 2 varchar (30), kab ntawv 3 char (1), kab lus hnub tim 4);
- Piv txwv li, los tsim lub rooj npe hu ua "Tsiaj" nrog ob kab "VARCHAR", ib kab "CHAR", thiab kab ntawv hnub, koj tuaj yeem ntaus cov lus txib hauv qab no:
tsim cov lus Pet_Animal (Lub npe varchar (20), Hom sib txawv (30), Tus txiv neej char (1), Hnub yug Hnub yug)
Kauj Ruam 3. Ntxiv kab rau lub rooj
Nrog qhov "ntxig" hais kom ua, koj tuaj yeem nkag cov ntaub ntawv xov xwm ntawm ib kab los ntawm kab hauv paus:
ntxig rau hauv table_name qhov tseem ceeb ('column1 tus nqi', 'column2 tus nqi', 'column3 tus nqi', 'column4 tus nqi');
-
Rau "Pets_Pet" cov lus siv ua ntej, koj kab ntawm cov ntaub ntawv yuav tsum zoo li no:
ntxig rau hauv Pet_Animal qhov tseem ceeb ('Fido', 'Husky', 'J', '2017-04-12');
- Koj tuaj yeem nkag lo lus NULL raws li kab lus kab lus yog tias kab ntawv tsis muaj.
Kauj Ruam 4. Nkag mus. Yog tias koj xav ua li ntawd, hla mus rau kauj ruam tom ntej.
Kauj Ruam 5. Tshaj tawm cov ntawv xa ntawv yog tias tsim nyog
Yog tias koj muaj cov ntaub ntawv khaws cia nrog ntau kab ntawm cov ntaub ntawv uas yuav ua rau mob yog tias koj yuav tsum tau ntaus lawv ib tus zuj zus, koj tuaj yeem xa cov ntawv sau uas muaj cov ntaub ntawv siv cov cai hauv qab no:
thauj cov ntaub ntawv hauv zos infile '/path/namaberkas.txt' rau hauv rooj nama_tabel kab txiav los ntawm '\ r / n';
-
Hauv qhov piv txwv "Pet_Animal", koj tuaj yeem ntaus cov cai hauv qab no lossis hais kom ua:
thauj cov ntaub ntawv hauv zos infile 'C: /Users/username/Desktop/pets.txt' rau hauv rooj Pets_Pets kab txiav los ntawm '\ r / n';
- Hauv Mac khoos phis tawj, koj yuav tsum siv cov kab hais kom ua "kab txiav los ntawm" nrog '\ r' hloov dua li '\ r / n'.
Kauj Ruam 6. Txheeb xyuas lub rooj tsim
Nkag mus rau cov ntaub ntawv qhia chaw; hais kom ua, tom qab ntawd xaiv lub database los ntawm kev ntaus ntawv xaiv * los ntawm lub npe;, nrog "npe" raws li lub npe database. Piv txwv li, yog tias koj siv "Pet_List" database, ntaus cov lus txib hauv qab no:
qhia databases; xaiv * los ntawm Pet_List;
Lub tswv yim
-
Nov yog qee qhov feem ntau siv hom ntaub ntawv:
- “ CHAR "(Ntev) - Qhov kev hloov pauv no muaj txheej txheej ntawm kab ntawv (hlua).
- “ VARCHAR "(Qhov ntev) - Qhov kev hloov pauv no muaj qhov ntev tshaj plaws ntawm cov hlua cim (raws li qhov sib txawv qhov ntev koj tau nkag mus).
- “ Cov ntawv " - Qhov sib txawv no muaj tus cim teeb nrog cov ntawv ntev tshaj plaws sib npaug rau 64 kilobytes.
- “ INT "(Qhov ntev)-Qhov sib txawv no yog 32-ntsis tus lej nrog tus lej siab tshaj plaws ntev (tus lej rho tawm lossis"-"suav tias yog" tus lej "rau tus lej tsis zoo).
- “ TUAG "(Ntev, zauv) - Qhov sib txawv no yog zauv zauv nrog tus nqi ntawm qhov ntev raws li tus lej tag nrho ntawm cov cim tshwm. Lub caij no, kab zauv zauv qhia ntau tus lej uas tuaj yeem tshwm tom qab tus lej
- “ HNUB ”-Qhov sib txawv no suav nrog hnub tim hauv xyoo-hli-hnub hom (####-##-##).
- “ SIJHAWM "-Qhov sib txawv no suav nrog lub sijhawm hauv ib teev-feeb-thib ob hom.
- “ ENUM ”(“Value1”,“value2”,….) - Qhov sib txawv no muaj cov npe ntawm tus lej lossis tus lej.
-
Nov yog qee qhov ntxiv uas koj tuaj yeem siv:
- “ TSIS NULL " - Nrog qhov ntsuas no, koj yuav tsum sau tus nqi. Cov kem tsis tuaj yeem tso tseg.
- “ DEFAULT "Default-value-Yog tsis muaj cov ntaub ntawv lossis tus nqi nkag mus, lub neej ntawd-tus nqi yuav raug ntxiv rau kab ntawv tau txais.
- “ YEEB NCUAB " - Hauv cov lej lej, qhov ntsuas kom ntseeg tau tias tus lej nkag yuav tsis yog tus lej tsis zoo.
- “ AUTO_INCREMENT " - Nrog qhov ntsuas no, tus nqi yuav nce ntxiv txhua lub sijhawm koj ntxiv kab tshiab rau ntawm lub rooj.
Ceeb toom
- Yog tias MySQL server tsis ua haujlwm thaum koj sim nkag mus rau kab lus "mysql", koj tsis tuaj yeem txuas ntxiv cov txheej txheem no.
- Ib yam li lwm cov kev teev npe, nco ntsoov tias cov lus txib koj nkag mus tau ntaus nrog qhov sau kom raug thiab yov ua ntej koj sim nkag mus rau lawv.