µ±Ç°Î»ÖãºLinux½Ì³Ì - Linux - ÍøÂçÊý¾Ý¿â5Èս̳Ì(3)

ÍøÂçÊý¾Ý¿â5Èս̳Ì(3)



         Ô­×÷Õß:Richard Dice

    --------------------------------------------------------------------------------

    ÍøÂçÊý¾Ý¿â½Ì³Ì£­[µÚ£³Ìì]


    Ò» ÍøÂçÊý¾Ý¿â½Ì³Ì - µÚÈýÌì
    ¶þ ³£¹æµÄApacheÉèÖÃ
    Èý MySQLºÍÕû¸öÊý¾Ý¿â/·þÎñÆ÷ϵͳ
    ËÄ MySQL, SQL, DDL,ºÍDML
    Îå ÎÒÃDz»ÊÇÔÚ½¨Á¢»¥ÁªÍøÕ¾µãÂð£¬ÎÒÊDz»ÊÇ©ÁËʲô¶«Î÷£¿

    --------------------------------------------------------------------------------

    Ò»¡¢µÚÈýÌì

    ÍøÂçÊý¾Ý¿âÊÇÒ»¸öºÜ´óµÄ¿ÎÌ⣬ÓÃÒ»¸ö5ÌìµÄ½Ì³Ì²»¿ÉÄÜ̸µ½ËùÓеÄÄÚÈÝ¡£ÎÒΪÄã½ÌÊÚ»ù´¡µÄ֪ʶ£¬Ê£ÏµľÍÒª¿¿Äã×Ô¼ºÔÚʵ¼ùÖÐÌå»áºÍѧϰ¡£

    ÔÚ±¾½Ì³ÌÖÐÎÒÃÇÖ»ÓÐʱ¼ä½²½âÓÚÍøÂçÊý¾Ý¿âÓйصÄÉèÖÃÎÊÌâ¡£

    Apache

    ApacheÍøÂç·þÎñÆ÷ ÊÇÒ»ÏîÐÔÄÜÏ൱²»´íµÄÈí¼þ¡£¼òµ¥µØ˵£¬ËüµÄÄ¿µÄ¾ÍÊÇÈÃÓû§ÄÜ´ÓÄãµÄ¼ÆËã»úÖÐÇëÇóÍøÂçÐÅÏ¢¡£Í¨³£ÕâЩÐÅÏ¢ÊÇHTMLÍøÒ³ºÍͼÏó£¨GIFºÍJPEGͼÏ󣩣¬µ«ÊÇÏÖ´úµÄÍøÂç·þÎñÆ÷¶¼Ö§³ÖCGI (ÍøÂç±à³Ì£©¡£

    ÕâÊÇApache¼òµ¥°æ±¾µÄ¹¦ÄÜ¡£¶ÔÓÚÌض¨µÄÓ¦Óã¬ÄãÐèÒª¶ÔÆä½øÐÐÉèÖã¬ÈÃÆäÕæÕý·¢»Ó¹¦ÄÜ¡£

    ApacheµÄ¹¦ÄÜʵ¼ÊÉϷdz£Ç¿´ó£¬Äã¿ÉÒÔ¶ÔÆä½øÐжàÖÖÉèÖã¬Ö´ÐжàÖÖ¹¦ÄÜ¡£µ«ÏÖÔÚÎÒÃÇÖ»Äܽ²½âÓйØÍøÂçÊý¾Ý¿âµÄÉèÖ᣽ñÌìËù½²µÄÐèÒªºÍApacheÆäËûµÄÎÄÏ×»òÎÒÃÇÔÚÕâÀïʹÓõÄÈí¼þ°üÒ»ÆðÓ¦Óá£


    ¶þ¡¢³£¹æµÄApacheÉèÖÃ

    ½øÐг£¹æApacheÉèÖãº

    ¡¡

    Ñ¡ÔñDocumentRoot×ÓĿ¼
    ePerl
    mod_perl
    DocumentRoot¸ÅÄî±È½ÏÈÝÒ×Àí½â¡£¼ÙÉèÎÒÃÇÉèÁ¢ÁËÓòwww.example.com¡£¶øURL¿ÉÄÜÈçÏÂËùʾ£º

    http://www.example.com/webmonkey/day3.html
    ÎÒϲ»¶½«ÎÒµÄDocumentRootÉèÖÃΪ/web/docs/£¬ÕâÑùÒÔÀ´£¬Ïà¶ÔÓ¦ÓÚ¸ÃURLµÄÎļþ½«ÊÇ/web/docs/webmonkey/day3.html.

    ¼ÙÉèÄã°´ÕÕÎÒ×òÌìµÄ¿Î³ÌÖеĽ¨Òé°²×°ÁËApache£¬ÔòÄãÐèÒª±à¼­/usr/src/apache_1.2.6/conf/srm.conf½«DocumentRootÉèÖÃΪ/web/docs¡£ (±à¼­·½·¨ºÜ¼òµ¥£¬ÄãÒ»¿´¾ÍÖªµÀ¸ÃÔõô×ö¡£Ä㻹ÐèÒªÏàÓ¦¸Ä±ä/usr/src/apache_1.2.6/conf/access.conf. (Ò²²»ÄÑ)¡£ÔÚUnixÌáʾ·ûÏ£¬×¢ÒâÒ»¶¨ÒªÊµ¼Ê½¨Á¢¸ÃDocumentRoot×ÓĿ¼£º

    mkdir /web; mkdir /web/docs
    PerlºÍePerl (½«ÊÇÃ÷ÌìµÄÖ÷Òª¿Î³ÌÄÚÈÝ),ºÍmod_perlÒ»Æð¾Í¿É½¨Á¢ÆðÊÀ½çÒ»Á÷µÄÊý¾Ý¿âÖ§³ÖϵÄÍøÕ¾¡£ËõÍ·µÄ¿Î³ÌÖÐÎÒ½¨ÒéÄãÃÇʹÓÃÁËmod_perlµÄ×Ô¶¯Apache´´Á¢¹¦ÄÜ£¬ËùÒÔÏÖÔÚÄãÓ¦¸ÃÓÐÁËÕâÑùÒ»¸öÎļþ /usr/src/apache_1.2.6/src/httpd¡£

    ½ÓÏÂÀ´£¬ÄãÓ¦¸Ã£º

    µÚ1²½£º½¨Á¢/usr/src/apache_1.2.6/src/httpdºÍ/usr/sbin/httpdÖ®¼äµÄ±êÖ¾ÐÔÁ´½Ó¡£
    ½¨Á¢±êÖ¾ÐÔÁ´½ÓµÄÒâÒåÊÇ£ºÄãµÄLinux²Ù×÷ϵͳϣÍûhttpd·ÅÖÃÔÚ/usr/sbin×ÓĿ¼ÖУ¬µ«ÊÇÒÔºó¶ÔhttpdµÄÈκÎÖØеÄÉèÖý«°ÑËü¸ÃÔÚ/usr/src/apache_1.2.6/srcÏ¡£Õû¸öÌصãʹÄãÎÞÐèÿ´Î½«httpd¿½±´µ½/usr/sbinÏ¡£
    cd /usr/sbin

    ln -s /usr/src/apache_1.2.6/src/httpd httpd
    µÚ2²½£º¼ì²éÈ·±£ÄⶨÉèÖÃÖаüÀ¨ÁËmod_perl¡£
    ÏÖÔÚÎÒÃÇ×öÒ»¸ö¿ìËÙ¼ì²é£¬¼üÈëÒÔÏÂÖ¸Á
    /usr/sbin/httpd -v
    ÆÁÄ»½«ÏÔʾһÌõ¶ÌÐÅÏ¢£º

    Server version Apache/1.2.6 mod_perl/1.08.
    µÚ3²½¡±ÉèÖÃÄãµÄ/etc/rc.d/rc.MÎļþ¡£
    ¸ÃÎļþºÍDOSµÄ×Ô¶¯Åú´¦ÀíÎļþ£¨autoexec.bat£©ÀàËÆ¡£ËüÔÚÄãµÄLinux·þÎñÆ÷Æô¶¯Ê±ÔËÐС£È·±£Ê¹ËùÓбØÒªµÄÖØж¼±»³õʼ»¯²¢ÔÚbootʱÄܹ»Õý³£ÔËÐС£Èç¹ûÄãµÄrc.MÎļþÖÐûÓÐÒÔÏÂÉèÖã¬ÄãÓ¦¸Ã¼ÓÈ룺
    # Start Web server:

    if [ -x /etc/rc.d/rc.httpd ]; then

    . /etc/rc.d/rc.httpd

    fi
    ÕâЩ´úÂëÒâ˼ÊÇ˵£ºLinuxµÄÆô¶¯¹ý³Ì½«¼¤»îÎļþ/etc/rc.d/rc.httpdµÄÄÚÈÝ (ÒÔÆô¶¯ÄãµÄhttpd)¡£Õâʱ£¬ÆÁĻӦÏÔʾ£º

    echo httpd

    /usr/sbin/httpd -f /usr/src/apache_1.2.6/conf/httpd.conf &
    »òÐíÄ㻹ûÓÐÕû¸öÎļþ£¬ËùÒÔÄãÐèÒªÉú³É¸ÃÎļþ

    µÚ4²½£ºÊ¹ApacheÄܹ»´¦ÀíCGIºÍePerlÎļþ¡£
    ÏÖÔÚÄãÐèÒª½øÐдóÁ¿Ï¸½ÚµÄÉèÖ᣻ص½/usr/src/apache_1.2.6/conf×ÓĿ¼£¬È»ºó£º
    ÔÚaccess.confÖУ¬È·±£ÒÔ¼ÓÖØ×ÖÌå(bold)¼ÓÈëÏÂÁÐÎÄ×Ö£º



    Options Indexes FollowSymLinks ExecCGI

    AllowOverride None

    order allow,deny

    allow from all


    ÏÖÔÚ£¬ÐÞ¸Äsrm.conf:

    DirectoryIndex index.iphtml index.cgi index.html
    Ä㻹ÐèÒª\"uncomment\" ijÐУ¬ËùÒÔ×îºóµÄÉèÖÃΪ£º

    AddHandler cgi-script .cgi
    ÔÚhttpd.confÖУ¬, ÔÚÇøÓòÖ®ÉϼÓÈëÒÔÏÂÎÄ×Ö£º

    Perlrequire /web/docs/startup.perl



    PerlModule Apache::ePerl



    SetHandler perl-script

    PerlHandler Apache::ePerl


    ÏÖÔÚÄãµÄ/web/docs×ÓĿ¼ÏÂÐèÒªÒ»¸östartup.perlÎļþ£¬Äã¿ÉÒÔ¿½±´Îҵģº

    #!/usr/bin/perl

    use strict;

    use Apache::Registry;

    use CGI;

    use DBI ();

    1;
    ¡¡

    ȱʡÇé¿öÏ£¬³ýÁËÄãÖ¸¶¨µÄ/cgi-bin/×ÓĿ¼֮Í⣬Apache²»»áÔÊÐíCGI³ÌÐòÔÚÈκÎÆäËû×ÓĿ¼ÖÐÔËÐУ¬Èç¹û°²È«ÐÔÊÇÄãµÄÊ×Òª¿¼ÂÇ£¬ÕâÒ»ÌõºÜÖØÒª¡£µ«ÓÉÓÚÏÖÔÚÎÒÃÇ̸µÄÊÇÍøÂçÊý¾Ý¿â±à³Ì£¬ËùÒÔÔÚµÚ4²½ÖеÄÉèÖÃÈÃApacheÔËÐÐCGI³ÌÐòÔÚÆäËû×ÓĿ¼ÖÐÒ²ÄÜÔËÐС£

    ÎÒÃÇ»¹¸æËßApacheÓöµ½´øÓÐÌØÊâºó׺.iphtmlµÄÎļþʱӦ¸ÃÔõô×ö¡£ÕâÖÖÎļþ½Ð×öÄÚ²¿ÆÊÎöºóµÄHTMLÎļþ¡£ÏÖÔÚApacheÖªµÀÓ¦¸Ã½«ÕâÖÖÎļþת½»ePerl½øÐнøÒ»²½µÄ´¦Àí¡£×îºó¡£ÎÒÃǸæËßApacheÔÚ·þÎñÆ÷³õʼ»¯Ö®ºóÁ¢¼´ÔËÐÐÎļþstartup.perl¡£¸ÃÎļþ°Ñ¼¸¸ö·Ç³£ÓÐÓõÄÄ£¿éÔØÈë·þÎñÆ÷Äڴ棬ÖØÒªÖ®ºóµÄ³ÌÐòÐèҪʹÓÃÕâЩģ¿éʱ¾Í ÎÞÐèÖØÐÂÔØÈëËüÃÇ¡£

    ¡¡

    Èý¡¢MySQLºÍÕû¸öÊý¾Ý¿â/·þÎñÆ÷ϵͳ

    ÔÚµÚ1ÌìµÄ½Ì³ÌÖУ¬ÎÒÁ˽âÁËÊý¾Ý¿â·þÎñÆ÷³£×¤ÄÚ´æ²¢¿ÉÒÔ»ØÓ¦ÇëÇó¡¢´æ´¢Êý¾Ý¡¢Ìṩ¹ÜÀí½çÃæÈ·±£Êý¾ÝÖ»ÄÜÔÚÊÚȨ·¶Î§ÄÚ±»´¦Àí¡£ÏÖÔÚÎÒÃǽ«Ê¹ÓÃMySQLÀ´Êµ¼ùÕâЩ¸ÅÄî¡£

    ¡¡

    ½¨Á¢ºÃÄãµÄMySQLºó£¬ÄãÐèÒª½øÐеÄÉèÖñÈÆð¶ÔApacheµÄÉèÖþÍÉÙ¶àÁË¡£Ö´ÐÐÍêÍêÕûµÄMySQL°²×°¹ý³Ì(°üÀ¨ÔËÐÐ/usr/local/src/mysql-VERSION/scripts/mysql_install_db)ºó£¬»¹ÓÐÒ»Ï×÷ÐèÒªÖ´ÐУº½«ÆäÉèÖÃΪ³£×¤ÄÚ´æµÄÊØ»¤³ÌÐò¡£Õâ¸ö¹ý³ÌºÍÎÒÃǶÔhttpdµÄ×ö·¨Ïàͬ¡£±à¼­/etc/rc.d/rc.M ÎļþʹÆä°üÀ¨ÒÔÏ´úÂ룺

    # Start mysql database server:

    if [ -x /etc/rc.d/rc.mysql ]; then

    . /etc/rc.d/rc.mysql

    fi
    Éú³ÉÏàÓ¦µÄrc.mysqlÎļþ¡£·Ç³£¼òµ¥£º

    /usr/local/bin/mysql.server start
    µ±ÎÒʹÓÃMySQLʱ£¬ÎÒ¾­³£Ê¹ÓÃÕâÁ½¸ö³ÌÐò£º/usr/local/bin/mysqlºÍ/usr/local/bin/mysqlshow¡£Äã²»ÐèÒª¼üÈëËùÓÐÕâЩÄÚÈÝ£¬- mysqlºÍmysqlshow¾ÍÄܹ»Õý³£¹¤×÷£¬ÒòΪ/usr/local/binÊÇÖ¸Áî·¾¶µÄ»·¾³±äÁ¿µÄÒ»²¿·Ö¡£

    ÈÃÎÒÃÇÊÔһϣº

    rdice:# mysqlshow

    +-----------+

    | Databases |

    +-----------+

    | mysql |

    | test |

    +-----------+
    Õâ¾ÍÊÇÄãÓ¦¸Ã¿´µ½µÄ£¨¼ÙÉèÄãÒѾ­ÕýÈ·°²×°ÁËPerlºÍData::ShowTable)¡£ÕâÏîÊä³öÏîÎÒÃÇÏÔʾÁË£ºMySQLÔÚ×î¸ß¼¶±ðÉϽ«Êý¾Ý°²Åŵ½Êý¾Ý¿âÖС£ÉÏÊöÁ½¸öÏÔʾÓÉMySQL×Ô¶¯Éú³É£¬Ã¿Ò»ÏÓÐÌØÊâÓÃ;£ºmysql±»MySQL×Ô¼ºÊ¹ÓÃÀ´Éú³É³ÌÐò×Ô¼ºµÄÄÚ²¿ÉèÖã¬test×÷ΪijÖÖÔÝ´æÇø¹©ËùÓÐÓû§Ê¹Ó㬵«ÊÇËüûÓÐÈκΰ²È«·À»¤»úȨÏÞÉèÖá£Ò²¾ÍÊÇ˵£¬²»Òª½«ÈκÎÖØÒªÐÅÏ¢·ÅÔÚtestÔÝ´æÇøÄÚ¡£

    ÎÒÃÇÔÙÀ´Ò»±é¡£µ«ÊÇÕâ´ÎÎÒÃǽ«ÓûÇómysqlshow¸æËßÎÒtestÊý¾Ý¿âÖеÄÄÚÈÝ£º

    rdice:# mysqlshow test

    Database: test

    +--------+

    | Tables |

    +--------+

    +--------+
    ±í¸ñ£¨Tables£©ÊÇÊý¾Ý¿âÖеÄÏÂÒ»¼¶¡£Äã¿ÉÒÔ½«±í¸ñÏëÏóΪµç×Ó¹¤×÷±í£ºÁУ¨columns£©´ú±íÊý¾ÝÓò£¬¶øÐУ¨rows£©Ôò´ú±íµ¥¸öµÄ¼Ç¼¡£

    ´ÓÆÁÄ»Êä³öÖÐÎÒÃÇ¿ÉÒÔ¿´µ½testÊý¾Ý¿âÊǿյġ£ÎÒÃǽ«ÅäºÏʹÓà mysql³ÌÐòºÍMySQL²¢ÔÚÊý¾Ý¿âÖзÅÈë¾ßÌåµÄÄÚÈÝ¡£

    ËÄ¡¢MySQL, SQL, DDL,ºÍDML

    ͬMySQLµÄ»¥¶¯½»Á÷Ö¸µÄÊÇÓÃËüµÄÓïÑÔSQL£¨½á¹¹»¯³ÌÐòÓïÑÔ£©¡£SQLÒ»°ã»®·ÖΪÁ½²¿·Ö£¬µÚ1²¿·Ö½Ð×öDDL£¬¼´Êý¾Ý¶¨ÒåÓïÑÔ£¨data definition language£©£¬ÄãÓÃSQLÕâ¸öµ¥Ôª¸æËßMySQLÈçºÎÉèÁ¢±í¸ñ¡£»¹ÓÐÒ»²¿·ÖÊÇDML£¬¼´Êý¾Ý¿ØÖÆÓïÑÔ£¨ data manipulation language£©£¬Õâ¸öµ¥ÔªÓÃÓÚ´ÓÄãµÄ±í¸ñÖлñÈ¡Êý¾Ý¡£

    ÕâÀïÊǼƻ®£ºÎÒ½«Æô¶¯mysql£¬Éú³ÉÒ»¸ö±í¸ñ£¬È»ºóÔÚ±í¸ñÖÐÊäÈëÊý¾Ý£¬È»ºó¼ì²éÎÒ¸ÕÊäÈëµÄÊý¾Ý¡£(ÎÒÓüÓÖØÌåÏÔʾµÄÎÄ×Ö½âÊ͸÷ÏîÖ¸ÁîµÄº¬Ò壩

    rdice:# mysql test

    Welcome to the MySQL monitor. Commands end with ; or \\g.

    Your MySQL connection id is 4 to server version:
    3.21.28-gamma-log



    Type \"help\" for help.



    mysql> create table albums ( ÕâÀïÎÒÔÚʹÓÃDDL
    -> title varchar(100), ÉèÖñí¸ñ£¬ÔÚ±í¸ñÖÐ
    -> artist varchar(100), ÎÒ½«´æ´¢Ò»Ð©
    -> released date); ÒôÀÖ×ÊÁÏ

    Query OK, 0 rows affected (0.07 sec)



    ÏÖÔÚÊÇDML£¬ÓÃÓÚ¸æËßMyDQLÔÚalbumÖмÓÈë¼Ç¼

    mysql> insert into albums(title,artist,released)

    -> values(\"Selling England By The Pound\",\"Genesis\",\"
    1973-01-01\");

    Query OK, 1 row affected (0.08 sec)



    ÕâÀïÊÇDMLÉùÃ÷£¬Ëü½«Ê¹ÎÒ¿´µ½ÎҸղżÓÈëµÄÄÚÈÝ
    ×¢Òâ*ÔÚSQLÓïÑÔÖÐÖ¸¡°ËùÓÐÁС±
    mysql> select * from albums;

    +------------------------------+---------+------------+

    | title | artist | released |

    +------------------------------+---------+------------+

    | Selling England By The Pound | Genesis | 1973-01-01 |

    +------------------------------+---------+------------+

    1 row in set (0.06 sec)
    ¡¡

    MySQLËùÈϿɵÄËùÓÐSQLµÄÓï·¨ÔÚMySQLÎÄÏ×Öж¼ÓÐÏêϸ˵Ã÷£¬ÄãËæʱ¿ÉÒÔ²éÔÄ¡£¼´Ê¹½ñÌìµÄ¿Î³ÌÒ²ÒѾ­Éæ¼°ÁËÐí¶à½ø³ö֪ʶ£¬ËùÒÔÄãÓ¦¸Ã×ÐϸÑо¿Ò»ÏÂËü¡£

    Éú³É±í¸ñµÄ¼¶±ðÓï·¨ÊÇ£º

    create table ±í¸ñÃû (

    ÁÐ1 ÁÐ1Êý¾ÝÀàÐÍ,

    ÁÐ2 ÁÐ2Êý¾ÝÀàÐÍ,

    ...

    ÁÐ_x ÁÐ_xÊý¾ÝÀàÐÍ

    )
    ¸÷ÁпÉÒÔʹÓõÄÊý¾ÝÀàÐÍ¿ÉÒÔÔÚMySQLÎÄÏ×ÖÐÕÒµ½¡£ÔÚ±¾ÀýÖÐÎÒʹÓÃÁË\"date\"Êý¾ÝÀàÐÍÒÔ¼°±äÁ¿³¤¶È×Ö·û´®¡£\"varchar\" ×Ö·û´®µÄ³¤¶ÈÓÉÔ¤ÉèµÄ³¤¶ÈÏÞÖÆ£¬ÔÚ±äÁ¿ÖУ¬ÊÇ100¡£

    Òª½áÊømysqlÖеÄÒ»¸öÉùÃ÷£¬ÄãÐèÒª¼üÈëÒ»¸ö·ÖºÅ£¬È»ºó»Ø³µ¡£mysql½«¸æËßÄãµÄ¡°query£¨SQLÖÐÈκÎÖ¸ÁîµÄÊõÓ¡±×´Ì¬£¬ÒÔ¼°´¦ÀíËùÓÃʱ¼ä¡£

    insert£¨²åÈ룩µÄÓïÑÔ¸ü¼òµ¥£º

    insert into ±í¸ñ(ÁÐ1,ÁÐ2,...,ÁÐ_x)

    values(value1,value2,...,value_x)
    ×Ö·û´®±ØÐëÓÃÒýºÅȦÆðÀ´¡£

    select£¨Ñ¡Ôñ£©ÊÇSQL·Ç³£ÓÐÓõÄÉùÃ÷£¬±ØÒªµÄʱºò£¬ËüµÄÓ÷¨¿ÉÄÜ»á·Ç³£¸´ÔÓ¡£

    Èç¹ûÔÚ¸ÃÊý¾Ý¿âÖÐÎÒ´æ´¢Á˼¸°Ù¸öÒôÀÖÎļþ£¬¶øÇÒÎÒÖ»Ïë¿´Ò»ÏÂÓÐGenesis´´×÷µÄ×÷Æ·£¬ÎҾͿÉÒÔÓÃselect·¢³öÒ»¸öÉùÃ÷²éѯÎÒËùÐèÒªµÄÄÚÈÝ£º

    select title, released

    from albums

    where artist = \"Genesis\"

    order by released
    Õâ´ÎÎÒ°´Ãû³ÆȦ¶¨ÁËÎÒËù¸ÐÐËȤµÄÁУ¬¶ø²»ÊÇÓÃ* ͨÅä·û¡£ÃüÁîÐÐwhere artist = \"Genesis\"ÏÞÖƱØÐë²éѯMySQL¼Ç¼ÖÐÓÉGenesis´´×÷µÄ×÷Æ·£¬ÎÒ»¹ÃüÁîMySQL½«¸Ã×÷Çú¼ÒµÄ³ªÆ¬°´ÕÕ·¢ÐÐÈÕÆÚÅÅÐò¡£

    ³ýÁËinsertºÍselectÖ¸Á»¹ÓÐÁ½ÖÖ»ù±¾µÄDMLÖ¸Áupdate£¨¸üУ©ºÍdelete£¨É¾³ý£©¡£ updateʹÄãÄܹ»¸Ä±äÔÚ±í¸ñÐÐÖд洢µÄÊý¾Ý£»deleteʹÄãÄÜɾ³ý±í¸ñÖеÄÒ»ÐС£

    ÕâЩָÁîµÄʹÓ÷¶Àý£º

    ÎÒ·¢ÏÖSelling England µÄ·¢ÐÐÈÕÆÚÊÇ2ÔÂ1ÈÕ¶ø²»ÊÇ1ÔÂ1ÈÕ¡£ËùÒÔÎÒ¸üÐÂ
    ÎҵļǼ£º

    mysql> update albums

    -> set released = \"1973-02-01\"

    -> where title = \"Selling England by the Pound\"

    -> and artist = \"Genesis\";

    Query OK, 1 row affected (0.03 sec)



    mysql> select * from albums;

    +------------------------------+---------+------------+

    | title | artist | released |

    +------------------------------+---------+------------+

    | Selling England by the Pound | Genesis | 1973-02-01 |

    | Wind & Wuthering | Genesis | 1976-01-01 |

    | We Can\"t Dance | Genesis | 1991-01-01 |

    +------------------------------+---------+------------+

    3 rows in set (0.00 sec)



    Èç¹ûÎÒÈÏΪÎÒ²»Ï²»¶Genesis ...

    mysql> delete from albums where artist = \"Genesis\";

    Query OK, 3 rows affected (0.00 sec)



    mysql> select * from albums;

    Empty set (0.00 sec)
    ʹÓÃ\"update\" ºÍ\"delete\" Ö¸Áîʱ£¬ÄãÐèÒªÓÃwhereÖ¸Ã÷²éѯÌõ¼þ£¨·ñÔòÄãµÄ±í¸ñÖеÄÿһÐж¼»á±»Ð޸Ļòɾ³ý£¬Äã±ØÐëСÐÄ)

    »¥ÁªÍøÖÐÓÐÒ»¸öºÜºÃµÄSQL½Ì³Ì£¬ÎÒ½¨Òé×ÐϸÔĶÁ¸Ã½Ì³Ì¡£Ëü²¢²»ÍêÈ«ÊÊÓÃÓÚMySQL£¬ÕâÊÇÒòΪSQLÒ²Óв»Í¬µÄ¡°·½ÑÔ¡±¡£¸Ã½Ì³ÌËù½²µÄÄÚÈÝ»ù±¾ÊÊÓÃÓÚMySQL£¬µ«ÓÐһЩϸ΢µÄÇø±ð£¬ÔÚMySQLµÄSQLÎÄÏ×ÖÐÓоßÌå˵Ã÷¡£

    ½ñÌìµÄ¿Î³ÌµÄ×îºó£¬ÎÒÃǽ«ÔÙ´ÎÑо¿Ò»ÏÂmysqlshow:

    rdice:# mysqlshow test

    Database: test

    +--------+

    | Tables |

    +--------+

    | albums |

    +--------+

    rdice:# mysqlshow test albums

    Database: test Table: albums Rows: 0

    +----------+--------------+------+-----+---------+-------+

    | Field | Type | Null | Key | Default | Extra |

    +----------+--------------+------+-----+---------+-------+

    | title | varchar(100) | YES | | | |

    | artist | varchar(100) | YES | | | |

    | released | date | YES | | | |

    +----------+--------------+------+-----+---------+-------+
    mysqlshow¼Ç¼ÁËÎÒÃÇÔÚmysqlÖÐËù×÷µÄÒ»Çй¤×÷¡£µ±ÄãÒªÇómysqlshowÏÔʾ±í¸ñÐÅϢʱ£¬Ëü²¢²»¸æËßÄãÔÚ±í¸ñÖоßÌåÓÐʲôÐÅÏ¢£¬ËüÖ»ÊǸæËßÄã±í¸ñÖÐÄ¿Ç°ÓжàÉÙÐУ¬Ëü¸æËßÄãµÄÊDZí¸ñµÄ½á¹¹¡£ÎÒÃÇÒѾ­Á˽âÁË\"Field\"ºÍ\"Type\" £¬ÆäËûµÄ±í¸ñ×ÊÁÏÄê¿ÉÒÔ´ÓMySQLµÄÎÄÏ×ÖÐÕÒµ½ÏêϸÄÚÈÝ)¡£

    Îå¡¢ÎÒÃDz»ÊÇÔÚ½¨Á¢»¥ÁªÍøÕ¾µãÂð£¬ÎÒÊDz»ÊÇ©ÁËʲô¶«Î÷£¿

    ÎÒÃÇÏÖÔÚÒѾ­Á˽âÁËÊý¾Ý¿âµÄ»ù±¾ÖªÊ¶¡£ÏÂÃæÎÒÃǵÄÈÎÎñÊǽ«ÕâЩSQL¼¼ÊõÓ¦Óõ½»¥ÁªÍøÖС£ÎÒÃǽ«ÓÃDBI£¨PerlµÄÊý¾Ý¿â½çÃ棩ʵÏÖÕâһĿµÄ¡£ÎÒ½«SQLÓïÑÔÖ±½ÓдÈëePerl³ÌÐòÖУ¬²¢ÓÃPerlµÄDBIÄ£¿éÖ§³ÖÆäÔËÐС£

    ²»Òª×ż±¡£ÎÒÃÇÒѾ­½¨Á¢ÁËϵͳ£¬Ê£ÏµÄÖ»ÊDZàÂë¡£

    ·¢²¼ÈË:netbull À´×Ô:LinuxÊý¾Ý¿âÓ¦ÓÃÖ¸ÄÏ