Kushandisa MySQL ne Basic SQL Mirairo

Muchidimbu: Dzidza kushandisa mashoma SQL mirairo munzvimbo yakasununguka yekuchengetedzwa kwemasvomhu yekuchengetedza database MySQL.

MySQL ndiyo inowanzoshandiswa relational database manager. Kusununguka kwaro kushandiswa uye chekuvhara bvumirano chekushandisa zvakakonzera zvikuru mukudanana uku.

Vhiki rakapera, ndakafukidzika kuisa nekugadzirisa MySQL mu Ubuntu. Muchikamu chino ndichave ndichikupa mazita akawanda MySQL zvinhu, kunyanya kunamatira ku zvinokosha.

Cherechedza: MySQL mibvunzo (mirairo) ndeye nyaya-isinganzwisisiki; zvisinei, zvinowanzoshandiswa kushandisa ALL CAPS nokuda kwemurairo chaiwo mazwi akadzama uye lowercase nokuti zororo.

Basic Sql Mirairo
Basic Sql Mirairo

Kubatanidza ku & Kuregedza kubva kune MySQL Server

Kugona kukwanisa kupinda mibvunzo, iwe uchatanga kutanga kushamwaridzana neyo server uchishandisa MySQL uye shandisa MySQL nokukurumidza. Murairo wekuita izvi ndewokuti:

mysql -h host_name -u user -p

-h inoshandiswa kutsanangura a zita zita (kana sevha iri pane imwe mishonga; kana isiri iyo, ingoisiya), -u inotaura nezve mushandisi uye -p inotsanangura kuti iwe unoda kuisa a pasiwedhi.

Kunyange zvazvo isingakurudzirwe (nekuda kwezvikonzero zvekuchengeteka), unogona kuisa pasi password zvakananga mumurairo kuburikidza nekuichengeta munguva pfupi -p. Somuenzaniso, kana password ye test_user is 1234 uye uri kuedza kubatanidza pamushandisi wauri kushandisa, unogona kushandisa:

mysql -u test_user -p1234

Kana iwe ukabudirira kuisa mamiririri anodiwa, iwe uchakwaziswa ne MySQL shell nokukurumidza (mysql>):

MySQL Shell Prompt

To kubvisa kubva pane server uye siya the mysll prompt, type:

QUIT

Typing siya (MySQL ndeyekusaziva) kana q ichashandawo. Dhinda pinda kuti abve.

Iwe unogona zvakare kutengesa mashoko pamusoro payo mhandonemurairo wakajeka:

sudo mysqladmin -u root version -p

Cherechedza: Iva nechokwadi chokuti wakabatana nevharesi usati waisa chero ipi yeipi mibvunzo yandichave yakavhara.

Kana uchida kuona a urongwa hwezvingasarudzwa, shandisa:

mysql --help

Kushandisa Queries muMySQL

MySQL inochengeta data mu matafura uye anoshandisa mirairo inonzi mibvunzo (SQL = shanduro yemibvunzo yakagadzirwa). Ndisati ndapedza kupinda, kuchengetedza nekugadzirisa deta, ndichaenda mibvunzo inokosha saka iwe unowana hombe yacho.

Sezvo MySQL inoshandisa matafura, i Output of mibvunzo ichataridzwawo mukati matafura. Zvose zvinyorwa zveSQL zvinofanira kuteverwa ne semicolon (;), kunyange kune zvisizvo (zvikurukuru: QUIT). Unogona kuparadzanisa mbiru ne comma (,). Heano mimwe mienzaniso inokosha:

mysql> SELECT VERSION();
mysql> SELECT CURRENT_DATE;
mysql> SELECT VERSION(), CURRENT_DATE;

Somuenzaniso, mubvunzo wechitatu unodhinda chimwe chinhu chakafanana neizvi:

+-----------+--------------+
| VERSION() | CURRENT_DATE |
+-----------+--------------+
| 8.0.15    | 2019-04-13   |
+-----------+--------------+
1 row in set (0,41 sec)

kubva semicolon (;) inoratidza kuguma kweshoko, iwe unogona kunyorawo mazwi akawanda pane rimwe chete.

Somuenzaniso, panzvimbo ye:

mysql> SELECT VERSION();
mysql> SELECT CURRENT_DATE;

Unogona kunyora zvakare:

mysql> SELECT VERSION(); SELECT CURRENT_DATE;

Unogonawo kupinda mhando-mitsara mibvunzo (kana iwe usingaverengi a semicolon pamagumo emutsetse usati wapfuurira pinda). Muchiitiko ichocho, MySQL inongopinda muchirongwa chakasiyana kuti ikubvumire kuti urambe uchiraira. Semuyenzaniso:

mysql> SELECT
    -> VERSION()
    -> ,
    -> CURRENT_DATE;

Miti-mitsara mibvunzo ichaitika zvakare kana iwe usina kupedza tambo pamutsara (shoko rakakombwa ne ' or ").

Kana uchida kanzura mubvunzo, tanga mukati c uye tigoshingairira pinda.

Pane inokurudzira uye zvinoreva zvakasiyana:

  • mysql> = kugadzirira mutsva mutsva
  • -> = kurindira mutsara unotevera wemibvunzo yakawanda-mutsara
  • '> = kurindira mutsara unotevera, kumirira kukwaniswa kwetambo yakatanga nekodhi imwechete (')
  • "> = kurindira mutsara unotevera, kumirira kupedzerwa kwetambo yakatanga nekodhi mbiri (")
  • `> = kurindira mutsara unotevera, kumirira kupedzisa kwechiratidzo chakatanga nemusana (`)
  • / *> = kurindira mutsara unotevera, kumirira kupedzisa kwemazwi akatanga ne /*

Unogonawo kudhinda iyo Current time (hh: mm: ss) pamwe chete nezuva razvino NOW (), Uyewo mushandisi iwe wakabatana sekushandisa USER ():

mysql> SELECT NOW();
mysql> SELECT USER();

Izvi zvichaita chimwe chinhu chakafanana neizvi:

+---------------------+
| NOW()               |
+---------------------+
| 2019-04-13 23:53:48 |
+---------------------+
1 row in set (0,00 sec)

+----------------+
| USER()         |
+----------------+
| [email protected] |
+----------------+
1 row in set (0,00 sec)

MySQL inokubvumira kuverenga mathematics magwaro naizvo:

mysql> SELECT COS(PI()/3), (10-2+4)/3;

Kubudisa:

+--------------------+------------+
| COS(PI()/3)        | (10-2+4)/3 |
+--------------------+------------+
| 0.5000000000000001 |     4.0000 |
+--------------------+------------+

Kushandisa Databases muMySQL

1. Kuwana Ruzivo Pamusoro peDatabases

Chokutanga pane zvose, unogona rondedzero dziripo databases pamwe:

mysql> SHOW DATABASES;

Iwe unogonawo kuona iyo sarudza database pamwe:

mysql> SELECT DATABASE();

Izvi zvichaitika null kana hakuna database yakasarudzwa. Heanoi muenzaniso unotumirwa wezvirevo zviviri zvakataurwa:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

+------------+
| DATABASE() |
+------------+
| NULL       |
+------------+

2. Kuumba Databases

Izvi zvinoitwa nekungopinda mutemo:

mysql> CREATE DATABASE example_db;

Cherechedza: MuUbuntu 18.04 (kana chero imwe Unix-based system) mazita epa database uye mafura ari case-sensitive.

3. Kusarudza Databases

Kusarudza database, unofanira kutaura kuti unoda shandisa it:

mysql> USE example_db;

Kana ukabudirira, uchawana shoko:

Database changed

Kana usina kubudirira, uchadzoka zvakare mhosho kukuudza iwe kuti MySQL haigoni kuwana tsvakurudzo yakanyorwa.

Iwe unogonawo kusarudza dhesi yepamusoro paunosangana kune sevhari nekutaura zita redhesi yekare iripo pakuguma kwekubatanidza murairo:

mysql -h host_name -u user_name -p example_table

Semuyenzaniso:

mysql -u root -p example_table

Kushandisa Tables muSQL

1. Kuwana Tsanangudzo Pamatafura

Kunyora mafuraji ari pasi rekushandisa, shandisa:

mysql> SHOW TABLES;

Cherechedza: Iva nechokwadi chokuti wakasarudza database.

Kana iyo database isina chinhu (semuenzaniso ichangobva kusikwa), zvakabuda zvichave:

Empty set (0,00 sec)

Mushure mokusika matafura, izvo zvabuda zvichave pamwe nemutsara we:

+----------------------+
| Tables_in_example_db |
+----------------------+
| table_1              |
| table_2              |
+----------------------+
1 row in set (0,00 sec)

2. Kuumba Tables

Kuti ugadzire matafura, unofanirwa kujekesa chimiro - mapuranga uye rudzi rwepi ravanofanira kuchengeta.

Muenzaniso wangu, ndichachengetedza ruzivo pamusoro peboka revanhu: zita, zuva rokuberekwa, zvepabonde, nyika. Pano ndipo pandingaita sei tafura iyi:

mysql> CREATE TABLE table_1 (name VARCHAR(30), birth_date DATE, sex CHAR(1), country VARCHAR(40));

Cherechedza: Iwe unogonawo kunyora murairo pamiganhu yakawanda.

Unogona kuona kuti ndakataura zita retafura (tafura_1) uye zita remitambo (zita, birth_date, pabonde, nyika). Mushure memazita emakoromari, ndakatsanangura Data data vanochengeta. VARCHAR (n) ndiwo masimbi ehuwandu hwe n vanhu vari murefu, DATE inotsanangurwa (CCYY-MM-DD format) uye CHAR (1) zvinoreva chimiro chimwechete (kunyanya, ini ndinoda kushandisa 'm' uye 'f' nokuti mukono uye chikadzi). Mimwe mizhinji inowanikwa inosanganisira INT (integers), BOOL (booleans), NGUVA (hh: mm: ss), kune zvakawanda Data types inowanikwa kushandisa muMySQL (numeric, tambo, zuva uye nguva). Iwe unogonawo kushandisa zvinorema zvakasiyana siyana zvekutsvaga, zvakadai AUTO_INCREMENT.

Tafura ichaonekwa zvino kana iwe Ratidza TABLES.

Kana uchida, iwe unogona shandura chimiro we tafura uchishandisa ALTER TABLE:

mysql> ALTER TABLE table_1 ADD email VARCHAR(50);
mysql> ALTER TABLE table_1 DROP birth_date;

Iyi mienzaniso akawedzera chinyorwa (muenzaniso wokutanga) uye akabvisa kori (muenzaniso wechipiri). Iwe unogona kutarisa mamwe mashoko pamusoro ALTER TABLE pano, sezvo yakashandiswa zvikuru zvakare.

3. Kurondedzera Tables

Iwe unogona kuona chimiro chetafura panguva ipi zvayo ne:

mysql> DESCRIBLE table_name;

Semuyenzaniso:

mysql> DESCRIBE table_1;

iri kubuda:

+------------+-------------+------+-----+---------+-------+
| Field      | Type        | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| name       | varchar(30) | YES  |     | NULL    |       |
| birth_date | date        | YES  |     | NULL    |       |
| sex        | char(1)     | YES  |     | NULL    |       |
| country    | varchar(40) | YES  |     | NULL    |       |
+------------+-------------+------+-----+---------+-------+
4 rows in set (0,00 sec)

4. Kuchenesa Tables

Mutsara wokubvisa matafura ndeokuti:

DROP TABLE table_name;

5. Kuisa Dhidhi MuTables

Kuti uise data, unofanirwa kujekesa maitiro aunogona kuiswa munharaunda imwe neimwe (muchirongwa chakafanana sechitsanangudzo chetafura). Nokuda kwezvinhu zvisina zvazvinobatsira kana zvisingazivikanwe zvaunofanira kushandisa null. Iva nechokwadi chekuti kwete-nhamba nhamba ne quotes (') kana double quotes ("). Maitiro anofanira kuparadzaniswa ne commas(,).

Heano mienzaniso kuna Smith naEmily:

mysql> INSERT INTO table_1 VALUES ('Smith', '1980-04-24', 'm', 'Argentina');
mysql> INSERT INTO table_1 VALUES ('Emily', '1994-07-19', 'f', NULL);

6. Kubvisa Tables

Kana uchida Zvisina chinhu tafura (bvisa zvose zvinyorwa), shandisa:

DELETE FROM table_name;

kushandisa WHERE, iwe unogona kuva sora mitsetse chaiyo:

DELETE FROM table_name WHERE col_name = value

Ini ndichaenda zvakadzama muzvikamu zvinotevera.

7. Updating Table Entries

Mutsara we updating in entry is:

UPDATE table_name SET col = 'value' WHERE conditions

Semuyenzaniso:

UPDATE table_1 SET country = 'France' WHERE name = 'Emily'

Kana iwe usingarevi mamiriro ezvinhu, zvinyorwa zvose zvichashandurwa.

8. Kudzorera Dhaibva Kubva Tables

Mutemo weMySQL wakashandiswa pakubvisa deta kunze kwematafura SELECT. Chimiro chemashoko akadaro ndechekuti:

SELECT what
FROM where
WHERE conditions;

Ini ndichaenda kune dzimwe nzvimbo dzekushanda, kuitira kuti unzwisise kuti ungabudisa sei izvo zvaunoda kubva pane dhesi.

a. Kusarudza zvose data

Chokutanga pane zvose, kushandiswa kwakanyanyisa kunoratidza data yose kubva a tafura. Semuyenzaniso:

mysql> SELECT * FROM table_1;

The wildcard (*) rinomirira zvose, tafura_1 ndiro tafura yandinobvisa kubva. Iwe unogona kuona kuti ndakasiya iyo WHERE chikamu; zvinosarudzwa kuva nemamiriro ezvinhu echasarudzwa.

b. Kusarudza imwe data

Chokutanga pane zvose ndichaenda kusarudza mitsetse.

Kuti usarudze mimwe mizere, unofanirwa kutsanangura mamiriro izvo zvakaderedza pasi data:

mysql> SELECT * FROM table_1 WHERE name = 'Smith';
mysql> SELECT * FROM table_1 WHERE sex = 'm';
mysql> SELECT * FROM table_1 WHERE birth_date < '1990-1-1';
mysql> SELECT * FROM table_1 WHERE sex = 'f' AND birth_date > '1991-1-1';
mysql> SELECT * FROM table_1 WHERE sex = 'm' OR country = 'France';
mysql> SELECT * FROM table_1 WHERE country IS NOT NULL;

Mumuenzaniso miviri yekutanga, ini ndinongo enzanisa nheyo (nyaya-isinganzwisisiki). Iwe unogona zvakare enzanisa values ​​like Mazuva uye integers ne comparator operators (>, <,> =, <=, =). <> rinoshandiswa kureva 'haina kuenzana'. Unogona kutsanangura multiple conditions kushandisa zvinonzwisisika operators (AND, OR). AND rine zvakakwirira kupfuura OR. Zviri nani kushandisa vanababa kana paine zvinhu zvakaoma zvakanyanya.

HASI NULL iyo nzira yokuratidza mitsetse chete isina kukosha kwekamuri yakataurwa. Iwe haugoni kushandisa arithmetic comparison operators ne null, sezvo inomiririra kukosha kusingawani (chigumisiro chichava null zvakare). Iwe unofanira kushandisa ISI NULL uye HASI NULL.

zvose zviri zviviri null uye vanobatwa se VENHEMA, vamwe vose se TRUE.

Iye zvino ndichavhara kuratidza mahwendefa chaiwo.

Kuti uite kudaro, unofanirwa kutsanangura mahwendefa aunoda kuratidzira, akaparadzaniswa nema-commas. Semuyenzaniso:

mysql> SELECT name, birth_date FROM table_1;

Unogonawo kubvisa kudzokorora data. Somuenzaniso, kana ndichida kuwana mazuva ose ekuberekwa (ndisati ndawana kukosha kwakapetwa kazhinji kana vanhu vazhinji vakazvarwa musi iwoyo), ndichashandisa:

mysql> SELECT DISTINCT birth_date FROM table_1;

Izvi zvinongoratidza chete DISTINCT zvabuda.

Kuti uwane zvakanyanya chaicho, unogona kuenzanisa kuratidza mamwe mapurisa ne mamiriro (WHERE):

mysql> SELECT name, sex FROM table_1 WHERE country = 'France' AND birth_date < '1991-1-1';

c. Kuchengetedza data

Kugadzirisa deta, unoshandisa ORDER_BY:

mysql> SELECT name FROM table_1 ORDER BY birth_date;

Iwe unogona kuona kuti ini ndakabatanidza izvi nekusarudza data yakananga. Murairo wepamusoro ucharatidza mazita kubva pane zvinyorwa zvose, zvakarayirwa kukwira urongwa nezuva rokuberekwa.

Unogonawo kuisa mukati achidzika urongwa:

mysql> SELECT name FROM table_1 ORDER BY birth_date DESC;

Kuronga rinogona kushandiswa pairi multiple columns. Semuenzaniso, kuronga mukuderedza kurongeka nezuva rokuberekwa, uye vanhu vakaberekwa panguva yakafanana mukukwira kurongwa nezita, ndinoshandisa:

mysql> SELECT name FROM table_1 ORDER BY birth_date DESC, name;

d. Kuronga mazuva

Unogona kuwana Current date kushandisa CURDATE (). Uchishandisa izvi uye rimwe gore, iwe unogona kuverenga mutsauko (semuenzaniso kuwana zera wemunhu) ne TIMESTAMPDIFF ():

mysql> SELECT name, birth_date, CURDATE(),
    -> TIMESTAMPDIFF(YEAR, birth_date, CURDATE()) AS age
    -> FROM table_1 ORDER BY age;

Heino zvakabuda kune muenzanisotafura_1:

+--------+------------+------------+------+
| name   | birth_date | CURDATE()  | age  |
+--------+------------+------------+------+
| Emily  | 1994-07-19 | 2019-04-13 |   24 |
| Danny  | 1992-08-04 | 2019-04-13 |   26 |
| Joanna | 1992-08-04 | 2019-04-13 |   26 |
| Joe    | 1985-03-11 | 2019-04-13 |   34 |
| Smith  | 1980-04-24 | 2019-04-13 |   38 |
+--------+------------+------------+------+

TIMESTAMPDIFF () inotora semafungiro ekushandisa kwechikwata ichi (YEAR) uye mazuva maviri (birth_date, CURDATE ()) iyo yekuverenga mutsauko. The AS (alias) keyword dzinoreva chikamu chinoita uye chinoita kuti zvive nyore kushanda nayo (mumuenzaniso uyu: kusarudza nezera).

Unogona kuverenga Graviton: A Minimalist Open Source Code Editor

Nokutaura pamusoro zvimwe zvikamu zvemazuva, unogona kushandisa GORE(), MWEDZI() uye DAYOFMONTH (), achishandisa zuva as nharo. Semuyenzaniso:

mysql> SELECT name, birth_date, MONTH(birth_date) FROM table_1;

Unogona enzanisa migumisiro (mwedzi, makore, mazuva) sezvinongoita nhamba dzese. Zvisinei, ku enzanisa izvi zvine zvinhu zvakadai sa inotevera mwedzi, haugoni kuwedzera kune CURDATE (), sezvo izvi zvinogona kuita kuti iwe uone mwedzi 13 kana zvimwe zvisina kudaro. Basa rakagadzirirwa nokuti ndizvo INTERVAL uye DATE_ADD ():

mysql> SELECT name, birth_date
       FROM table_1
       WHERE MONTH(birth_date) = MONTH(DATE_ADD(CURDATE(),INTERVAL 1 MONTH));

Iwe unogona kushandisa zvakare modulo operator (Mod):

mysql> SELECT name, birth_date
       FROM pet
       WHERE MONTH(birth_date) = MOD(MONTH(CURDATE()), 12) + 1;

kushandisa mazuva asina kukodzera vachadzoka null uye kubereka ZVENYEVERA, kuonekwa ne:

mysql> SHOW WARNINGS;

e. Kushandisa muenzaniso kufanana

Mu MySQL, _ Zvinomiririra chero mhando imwe chete uye % nokuda kwe0 + vanhu uye mapepa (zvakashata) nyaya-isinganzwisisiki. Panzvimbo ye = uye <>, kushandisa mapurogiramu aunofanira kushandisa SEZVAIITA uye HERE MUSI:

mysql> SELECT birth_date FROM table_1 WHERE name LIKE '%a%';
mysql> SELECT birth_date FROM table_1 WHERE name LIKE '%b';
mysql> SELECT birth_date FROM table_1 WHERE name LIKE 'c%';
mysql> SELECT * FROM table_1 WHERE name LIKE '___'; 

Iyi mienzaniso inosarudza mazuva ekuberekwa ezvinyorwa uko zita rine 'a'(muenzaniso wokutanga), unoguma ne'b'(muenzaniso wechipiri) kana kutanga ne'c'(muenzaniso wechitatu). Muenzaniso wekupedzisira unosarudza mutsara uko zita rine mazita matatu (zvitatu zvitatu zve '_').

Unogonawo kushandisa yakawedzerwa nguva dzose, pamwe REGEXP_LIKE () (zvakare REGEXP uye RLIKE operators). Nguva dzose mazwi haasviki nehuwandu hwemutungamiri uyu, asi unogona kutarisa mamwe mashoko pano.

f. Kuverenga migumisiro

Kuverenga deta inokosha uye inoshandiswa nevakawanda munyika chaiye. MySQL inoshandisa COUNT () nokuda kwemabasa akadaro. Muenzaniso wakajeka ndewe kuverenga zvinyorwa zvetafura:

mysql> SELECT COUNT(*) FROM table_1;

Unogonawo kuparadzanisa kuverengwa pakati mapoka. Somuenzaniso, ini ndaigona GROUP BY nyika uye kuratidza kuti ingani masangano ari munyika imwe neimwe:

mysql> SELECT country, COUNT(*) FROM table_1 GROUP BY country;

Iwe unogona kutaurira kunyange mamwe mapoka mapoka nekutumira mamwe mazamu eboka neboka. Semuyenzaniso:

mysql> SELECT country, sex, COUNT(*) FROM table_1 GROUP BY country, sex;

Izvi zvinogona kushandiswa pamwe chete WHERE kuti kuderedza zvakabuda.

Ngwarira paunenge uchiverenga. Kana iwe unotsanangura chero chimwe chinhu chinyorwa kunze kwe COUNT () uye usataurire mazamu akazotevera GROUP BY, iwe unogona kuwana mhosho or zvisingatarisirwi mhinduro(ona ONLY_FULL_GROUP_BY).

g. Kushandisa mafurafura akawanda

Ichi chinhu chaunogona kuita muchiitiko chakanyanya kuoma.

Semuenzaniso, fungidzira kune imwe tafura (tafura_2) iyo inochengeta zuva racho (zuva) nevaroyi vanhu (zita) akapinda misangano (musangano).

Iwe unogona kuratidza kuti vanhu vekare vari mumatafura aya ndeapi pavakapinda misangano:

mysql> SELECT table_1.name,
       TIMESTAMPDIFF(YEAR, birth_date, date) AS age,
       meeting
       FROM table_1 INNER JOIN table_2
         ON table_1.name = table_2.name;

Izvi zvichaita chimwe chinhu chakadai:

+-------+------+-----------------+
| name  | age  | meeting         |
+-------+------+-----------------+
| Emily |   21 | Dog Lovers Club |
| Emily |   22 | Dog Lovers Club |
| Emily |   23 | Hackathon       |
| Smith |   36 | TED Talk        |
| Smith |   38 | Footbal Match   |
+-------+------+-----------------+

Ini ndichaedza kutsanangura iyo syntax. For zita, taifanira kutaura tafura_1.name uye tafura_2.name, sezvo chikamu chiripo mumatafura maviri (for birth_date, zuva uye musangano hatina kufanira kutsanangura tafura, sezvo yakasiyana neimwe yei). Izvi zvinoshandisa zvinyorwa zvandakazvifukidza.

Chikamu chinofadza ndeichi:

       FROM table_1 INNER JOIN table_2
         ON table_1.name = table_2.name;

INNER JOIN inoisa matafura pamwe chete uye inotora mutsetse une chimwe chinhu chakafanana, chirevo chinotsanangurwa nenhoko rinokosha ON; munyaya iyi, apo mazita anowirirana.

Cherechedza: Iwe unogonawo kuisa pamwe chete tafura imwechete pachedu, zvichida kuenzanisa zviviri ZVIKUTO zvitsva.

Kushandisa Batch Mode muMySQL

Chimwe chinhu chakanaka ndechokuti batch mode. Panzvimbo peyo interactive shell, unogona kuisa zvinyorwa mu faira uye Execute ivo:

mysql -h host_name -u user_name -p < batch_file

Iwe uchazobvumirwa kuisa password (kana ichidiwa kumushandi). Kana uchida kuramba uchimhanya panzvimbo yekumira pane zvikanganiso, shandisa -Force.

Iwe unogona kunyange redirect the output kune imwe purogiramu kana kuti faira:

mysql -h host_name -u user_name -p < batch_file | less
mysql -h host_name -u user_name -p < batch_file > output_file

Unogonawo kuwana interactive output ne -t or echo output ne -v parameters.

Kana iwe uri mariri interactive MySQL shell uye unoda kumhanya script, shandisa imwe yeizvi mbiri:

mysql> source batch_file;
mysql> . batch_file;

Wrapping Up

Muchikamu chino, ndakapfeka nzira dzakasiyana dzaungashandisa MySQL to shandisa tabular databases, kunyange kuongorora mune zvimwe enderera features.

Ndinogona kufara kana mutungamiri uyu anobatsira vashandisi vanotambudza nevatangi. Kunyange kana iwe usingati uchitanga, ndinotarisira kuti unoverenga chimwe chinhu chausingazivi nezvazvo. Kana yakakubatsira iwe, regai tizive mumashoko!

mabviro