SlideShare una empresa de Scribd logo
1 de 86
Descargar para leer sin conexión
!


quot;quot;               #       $
             %       &



     (                           %
                 % (         %       &




                                         '
It is a RDBMS Developed, Distributed and Supported by MySQL AB

It is Open Source

It is Fast, Reliable and Easy to Use

It can work as Client/Server or as Embedded System.




                                                           )
Written in C and C++
Works on Many Platforms
It can Handle Multiple CPUs effectively if available
Provides Transactional and Non Transactional Storage Engines
Very fast Thread based Memory Allocation System
Supports In Memory Hash Tables
Tested with Purify and Valgrind for best performance
Handles Huge Databases
Portable Code




                                                               *
+
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 6
Server version: 6.0.3-alpha-community MySQL Community Server (GPL)

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
+--------------------+
| Database           |
+--------------------+
| information_schema |
| dbone              |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)


Database changed




                           ,
+----+---------+--------+
| id | name    | color |
+----+---------+--------+
| 1 | apple    | red     |
| 2 | cherry | red       |
| 3 | banana | yellow |
| 7 | grape    | black |
| 8 | mango    | yellow |
| 6 | goa      | green |
| 9 | suppota | brown |
| 10 | jack    | green |
+----+---------+--------+
8 rows in set (0.00 sec)




                             -
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(5)      | NO   | PRI | NULL    | auto_increment |
| name | varchar(25) | YES |       | NULL    |                |
| color | varchar(15) | YES |      | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)




                                                                  .
+---------+--------+
| name    | color |
+---------+--------+
| apple   | red    |
| banana | yellow |
| cherry | red     |
| goa     | green |
| grape   | black |
| jack    | green |
| mango   | yellow |
| suppota | brown |
+---------+--------+
8 rows in set (0.00 sec)




                           /
+----+--------+-------+
| id | name   | color |
+----+--------+-------+
| 1 | apple | red     |
| 2 | cherry | red    |
+----+--------+-------+
2 rows in set (0.00 sec)


+----+--------+--------+
| id | name   | color |
+----+--------+--------+
| 1 | apple | red      |
| 2 | cherry | red     |
| 3 | banana | yellow |
| 8 | mango | yellow |
+----+--------+--------+
4 rows in set (0.00 sec)
'
0$




        !



     ! !!    !     ! !!



            !             !   !
             quot; quot;    quot;


                                  )
0$
     !


           # $                 #       % &
     ' (            ( $& )
     ( (       *   ( $& )          + , -
                                    '
     (     # $                     #     % &
     ' (            ( $& )
     ( (       *   ( $& )          + ,
                                    '     -
           &       (.   /0
     (     # $                     #     % &
     ' (            ( $& )           + , -
                                      '
     ( (       *   ( $& )          + , -
                                    '
           &       ( 01 ' */



                                               *
0$
     2222 ' ' ( (
                       quot;quot;quot;quot;
     2222 ' ' ( ( 3 3 4 ' 4
                       '
                       4 4          quot;quot;quot;quot;         4 quot;4 quot;
             , &           &)
     334 ' 4
        '
         quot;             quot;
         quot;
                            /        '
     5                                   /   '
                   /        '
     5                          /        '


                                                          +
0$
             !                 (
                               (
                               (
                               (
             !           , (
                         , (
                         , (
                         , (

         !   0   &        6' ,         7

     !       /       5    6' ,     7
,
%&
quot;#$



'()*+ ,)#)(quot;+#'


           !       quot;                        #
quot;          $ % '%
              &
               (                   )
                           *            )
               quot;
+                      ,           -.
           $ %&                         -
/          0 %                 /
1              2       %       1



                                                -
)3)4 6- 5
               5 7

8          )- )- 6 -
             9 5       -.
                        94       :) 5 9 -
                                      )3

; < 2 %=   <#
            > !3 7 7)#        ?@ A
            < :              )#
           ;B . - .
             C #             8 B
$                            )
           8
$          quot; ))) :           3
           $   )3            )     )




                                            .
-. . +%quot;'
D                *       E           E        D    F=   2

66               *       E           E        66   F=   2

GH      HG           0       quot;   (       GH    2HG      F=   2




                                                                 '/
'
quot;,. (
#$ +quot;$ *+#)quot;-#'
.)                ( $ )
/                 *          .)

0                      $          .)

1                 '    ) $         .)

2                 (7       .)

3                 '        .)




                                        ''
quot;4 '+
$ $ *+#)quot;-#'
.)             ( $ )
5              *% ( . )

6              .8 .)

7                  7

8              9. 8 . )

99             8          .)

::             /          .)




                               ')
-&$
  (); *+#)quot;-#'
.)               ( $ )
55               *% ( . )

66               .8 .)

<                0:     .)

9                ;

:                /

9<               ;                 0:

:<               /            0:

=< :9            %    0:     .)

:<9              % //        .)

                 9. 8 . )

                                        '*
quot;,+# *+#)quot;-#'
.)                       ( $ )
     >       !       !   1    $<        7

                         1
                         1     .)

                         (7            .)

                         %    % // 5

                                   7

                         % // 5

                                   5

 ?                           &) #           '   $

         >       !       1    $<        7           8

                                                        '+
quot;,+# *+#)quot;-#'
.)               ( $ )
         ?       %                 &) #     '   $

                 %             8      0,)

         =       %      7 5

                 #         &   $      8     0,)

     ?           80; 09#

             ?   1 &)




                                                    '
',
ABS(x).
ABS(x).
& :=      !     1'23
 =
& :=      !     1 +'23
 =

CEIL(x)
& :=      ! !   1&'+23
 =
& :=      ! !   1 &'+23
 =

CONV(N,from_base,to_base)
CONV(N,from_base,to_base)
& :=      ! !4 5 617 8# #'23
 =>   ?
& :=      ! !4 5 617 8# -#-23
 => ?


                                '-
MOD(N,M).
MOD(N,M).
& :=   !    4 1)'#,23
 =
& :=   !    4 1)/& *23
                  '#
 = 6

FLOOR(x)
& :=   ! 9 44 1 &'+23
 =
& :=   ! 9 44 1 &'+23
 =

POW(X,Y)
& :=   ! $4 : 1'#'23
 =
& :=   ! $4 : 1'# '23
 = 6


                         '.
ROUND(N,M)
&    :=   !   4;5 1 &)'*#'23
 =   6
&    :=   !   4;5 1 &)'*#+23
 =   6

SQRT(x)
& :=      !      1*23
 =
& :=      !     1'/23
 = 6      quot; quot;quot;quot;

TRUNCATE(X,D)
& :=      !    ;5!      1&)'*#'23
 = 6
& :=      !    ;5!      1 ''# '23
 =


                                    )/
ASCII(str).
ASCII(str)
& :=     !    ! 1< 23
                 '<
 =
& :=     !    ! 1'23
 =
& :=     !    ! 1< =<
                    23
 =


BIN(N)
& :=     !    5 1 '23
 =@  ?


BIT_LENGTH(str)
BIT_LENGTH(str)
& :=     !    5 18 '823
 =



                          )
CHAR(N,... [USING charset_name])
                  charset_name])
& :=        ! !>   1,,# ' # - #, <
                           -)# < 23
 = @' A /@
& :=        ! !>   1,,# )#,,& 23
                       ,,& < )<
 = @' ' ' @

CONCAT()
& :=       ! !4 5 !   1<   <<<< <
                           # #  23
 = @' A /@
& :=       ! !4 5 !   1<   < 5;
                           #      #< <
                                     23
 = % //

CONCAT_WS(separator,str1,str2,...)
& :=      ! !4 5 !    ?: 1<<<
                           ##9            #
                                          <<              <<
                                                          #         5   <
                                                                        23
 =@      & B $         & B
                         / % & @
& :=      ! !4 5 !    ?: 1<<<
                           ##9            #
                                          <5 ;   #<   5        <
                                                               23
 =@      & B
           / % &       @


                                                                             )'
ELT(N,str1,str2,str3,...)
& :=      !           < >  #
                1 #< @#< @ < < @#<
                                <    <
                                     23
 =@ C
    @
& :=      !           < >  #
                1*#< @#< @ < < @#<
                                <    <
                                     23
 =@ @

FIELD(str,str1,str2,str3,...)
& :=      ! 9         < > < < >    #
                  1< @#< @#< @#< @ < < @#<
                                        <    <
                                             23
 =
& :=      ! 9        #> < < >      #
                  1< < < @#< @#< @ < < @#<
                                        <    <
                                             23
 =

FIND_IN_SET(str,strlist)
FIND_IN_SET(str,strlist)
& :=      ! 9 5 ? 5?    1< # # # <
                         %<< %# 23
 =
& :=      ! 9 5 ? 5?    17    # *+# ,#
                          '//<7 ,#    '//#)//<
                                             23
 =


                                                  ))
FORMAT(X,D)
& :=        ! 94    1 '))'& ')*+ #*23
 =@ B     6   @
& :=        ! 94    1 '))'& #*23
 =@ B     6   ?

HEX(N_or_S)
HEX(N_or_S)
& :=       ! > A1'++23
 =@ >
& :=       ! > A1< % <
                     23
 =


INSERT(str,pos,len,newstr)
INSERT(str,pos,len,newstr)
& :=       ! 5     1<        #
                             < )#*#<
                                   :    <
                                        23
 = @A D     $>
& :=       ! 5     1<        #
                             < #*#<
                                  :     <
                                        23
 = @A      $@

                                             )*
INSTR(str,substr)
INSTR(str,substr)
& :=       !   5    1<     % % << <
                               # % 23
 =
& :=       !   5     =% < <
                    1<  #          % <
                                     23
 =

LCASE(str)
LCASE(str)
& :=       !   !    17     $          823
 => & )        >
& :=       !   !     18)    B 5;     0 '//-<
                                           23
 =?    C           !?


INSERT(str,pos,len,newstr)
INSERT(str,pos,len,newstr)
& :=       ! 5        1<           #
                                   < )#*#<
                                         :      <
                                                23
 = @A D     $>
& :=       ! 5        1<           #
                                   < #*#<
                                        :       <
                                                23
 = @A      $@

                                                     )+
LEFT(str,len)
LEFT(str,len)
& :=       !    9 17         < +23
                             #
 =>   ?
& :=       !    9 1 ')*+ #)23
 => ?

LENGTH(str)
LENGTH(str)
& :=       !    5 C > 17     $        823
 =
& :=       !    5 C > 1 ')*+ 23
 =


LPAD(str,pos,len,padstr)
LPAD(str,pos,len,padstr)
& :=        !   $   17     $< ,# 23
                            # 8D<
 = >EEE/*' #>
& :=        !   $   17     $< '#
                            # 8D823
 = >/*@

                                            )
LTRIM(str)
LTRIM(str)
& :=     !           17                    823
 =>    ?
& :=     !           17             $             723
 =7  $                7

MID(str,pos,len)
MID(str,pos,len)
& :=       !        17     $            8# #+23
 =>   ?
& :=       !        1 ')*+ # '23
                            )#
 =? ?


REPEAT(str,count)
REPEAT(str,count)
& :=        !   $        17 < )23
                           > #
 = >3 3 3 >
& :=        !   $        1 /#'23
 =>     ?

                                                        ),
REVERSE(str)
REVERSE(str)
& :=        !   6        17:       823
 = > *D ?
& :=        !   6        1//,23
 = >,8

RIGHT(str,len)
RIGHT(str,len)
& :=        !   C > 17         $          8#)23
 => ?
& :=        !   C > 1 '///#)23
 =>   ?


RPAD(str,len,padstr)
RPAD(str,len,padstr)
& :=        ! $     17         $ < -#7
                                 # D823
 = >/*' #EEEE>
& :=        ! $     1/+/#*#+/23
 =>     ?

                                                  )-
SPACE(10)
& :=         !   $ ! 1 /23
 =>   ?
& :=         !   $ ! 1 -23
 = >8

TRIM(str)
TRIM(str)
& :=         !        17        $      823
 = >/*' #         ?
& :=         !        1                ')    23
 =>    ?


UNHEX(str)
UNHEX(str)
& :=         ! ; 5 > A17*!* * +/823
 = >/*' #>
& :=         ! ; 5 > A17*!* * +C 823
 = % //

                                                  ).
ADDDATE(date,INTERVAL expr unit)
ADDDATE(date,INTERVAL
& :=     !         17'//- / ) 8#    E '   23
 => !        ?
& :=     !         17'//- / ) 8#    E +        23
 => !        ?

CURDATE()
& :=     ! !;     123
 => !      ?
& :=     ! !;     12F .3
 =  !


DATEDIFF(exp1, exp2)
& :=     !       991 ( 12# .,+ /' /+823
                         8
 =   !
& :=     !       991 ( 12# .*, /- +823
                         8
 = !

                                                    */
MAKETIME(hr,min,sec)
MAKETIME(hr,min,sec)
& :=    !        G        1 '# +'23
                              */#
 =? 4 4 ?
& :=    !        G        1 '# +'23
                              */#
 = % //

CURTIME()
& :=      ! !;          123
 = ? 4 4 !?
& :=      ! !;          12F)/3
 =     !6


TIME_TO_SEC(x)
& :=     !           ? 4 ? !18 /H /)823
                                 '/H
 =
& :=     !           ? 4 ? !18)/H /)823
                                 '/H
 = quot;

                                          *
*'
Single line Query
mysql> select VERSION(), CURDATE() ;
+-----------------------+------------+
| VERSION()             | CURDATE() |
+-----------------------+------------+
| 6.0.3-alpha-community | 2008-01-21 |
+-----------------------+------------+
1 row in set (0.08 sec)

mysql>




                                         *)
Multiple line Query
mysql> select VERSION(); select curdate();
+-----------------------+
| VERSION()             |
+-----------------------+
| 6.0.3-alpha-community |
+-----------------------+
1 row in set (0.00 sec)

+------------+
| curdate() |
+------------+
| 2008-01-21 |
+------------+
1 row in set (0.00 sec)

mysql>




                                             **
The Delimiter (;)
mysql> select USER()
    -> ,
    -> CURDATE(),
    -> curtime();
+----------------+------------+-----------+
| USER()         | CURDATE() | curtime() |
+----------------+------------+-----------+
| root@localhost | 2008-01-21 | 12:18:56 |
+----------------+------------+-----------+
1 row in set (0.05 sec)

mysql>

Query Termination
mysql> select
    -> USER()
    -> c
mysql>

                                              *+
#-. *quot;' )%@ +)%$
                %&
#8. ' #              '
. A'B;
     9               8      F $ &&        6
09                   D       ,        &       )         $ &&      6
C
9                    D       ,       BF                $ &)
                                 F                :     + 6
                                                          G@H-
D9                   D       ,       BF                $ &)
                                 F                 :      + 6
                                                           GIH-
E9                   D       ,       BF               $ &)
                                     F            $< $< + H-
                                                         GJ 6
219                  D       ,       BF                $ &)
                     $ &&            F  KE6




                                                                      *
Creating and Using Databases
mysql> create database LAMP;
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> use LAMP;
Database changed
mysql>




                                      *,
Creating Tables
mysql> show tables;
Empty set (0.00 sec)

mysql> create table fruits(
    -> id int(5) auto_increment primary key,
    -> name varchar(25),
    -> color varchar(15)) engine=myisam;
Query OK, 0 rows affected (0.16 sec)

mysql> show tables;
+----------------+
| Tables_in_lamp |
+----------------+
| fruits         |
+----------------+
1 row in set (0.00 sec)

mysql>


                                               *-
Structure of the Table
mysql> desc fruits;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(5)      | NO   | PRI | NULL    | auto_increment |
| name | varchar(25) | YES |       | NULL    |                |
| color | varchar(15) | YES |      | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.05 sec)

mysql>




                                                                  *.
Working with Tables
mysql> select * from fruits;
Empty set (0.00 sec)

mysql> insert into fruits(name,color) value
('apple','red');
Query OK, 1 row affected (0.00 sec)

mysql> select count(*) from fruits;
+----------+
| count(*) |
+----------+
|        1 |
+----------+
1 row in set (0.00 sec)




                                              +/
Working with Tables
mysql> select * from fruits;
+----+-------+-------+
| id | name | color |
+----+-------+-------+
| 1 | apple | red    |
+----+-------+-------+
1 row in set (0.00 sec)

mysql> insert into fruits values ('1','orange','orange');
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
mysql>




                                                            +
The effects of auto increment
mysql> insert into fruits(id,name,color) values (‘2’,‘cherry’,’red’);
Query Ok, 1 row affected (0.00 sec)

mysql> insert into fruits(name,color) values (‘banana’,’yellow’);
Query Ok, 1 row affected (0.00 sec)

mysql> insert into fruits(id,name,color) values (‘7’,‘grape’,’black’);
Query Ok, 1 row affected (0.00 sec)

mysql> insert into fruits(name,color) values (‘mango’,’yellow’);
Query Ok, 1 row affected (0.00 sec)

mysql> insert into fruits(id,name,color) values (‘6’,‘goa’,’green’);
Query Ok, 1 row affected (0.00 sec)

mysql> insert into fruits values (null,‘suppota’,’brown’);
Query Ok, 1 row affected (0.00 sec)

mysql> insert into fruits(name,color) values (‘jack’,’green’);
Query Ok, 1 row affected (0.00 sec)




                                                                       +'
The effects of auto increment (Look at the id value)
mysql> select * from fruits;
+----+---------+--------+
| id | name    | color |
+----+---------+--------+
| 1 | apple    | red    |
| 2 | cherry | red      |
| 3 | banana | yellow |
| 7 | grape    | black |
| 8 | mango    | yellow |
| 6 | goa      | green |
| 9 | suppota | brown |
| 10 | jack    | green |
+----+---------+--------+
8 rows in set (0.00 sec)

mysql>




                                                       +)
Sorting the records
mysql> select name,color from fruits order by color;
+---------+--------+
| name    | color |
+---------+--------+
| grape   | black |
| suppota | brown |
| goa     | green |
| jack    | green |
| apple   | red    |
| cherry | red     |
| banana | yellow |
| mango   | yellow |
+---------+--------+
8 rows in set (0.00 sec)

mysql>




                                                       +*
Selection with conditions
mysql> select * from fruits where color='red';
+----+--------+-------+
| id | name   | color |
+----+--------+-------+
| 1 | apple | red     |
| 2 | cherry | red    |
+----+--------+-------+
2 rows in set (0.00 sec)

mysql> select * from fruits where color='red' or color='yellow';
+----+--------+--------+
| id | name   | color |
+----+--------+--------+
| 1 | apple | red      |
| 2 | cherry | red     |
| 3 | banana | yellow |
| 8 | mango | yellow |
+----+--------+--------+
4 rows in set (0.00 sec)



                                                                   ++
Selection with conditions
mysql> select * from fruits
    -> where (color='red' or color='yellow') and length(name) >
5;
+----+--------+--------+
| id | name   | color |
+----+--------+--------+
| 2 | cherry | red     |
| 3 | banana | yellow |
+----+--------+--------+
2 rows in set (0.00 sec)

mysql> select * from fruits where name like '%o%';
+----+---------+--------+
| id | name    | color |
+----+---------+--------+
| 8 | mango    | yellow |
| 6 | goa      | green |
| 9 | suppota | brown |
+----+---------+--------+
3 rows in set (0.00 sec)


                                                                  +
Selection with conditions
mysql> select * from fruits where name like '%a';
+----+---------+--------+
| id | name    | color |
+----+---------+--------+
| 3 | banana | yellow |
| 6 | goa      | green |
| 9 | suppota | brown |
+----+---------+--------+
3 rows in set (0.00 sec)

mysql> select * from fruits where name like '_a%';
+----+--------+--------+
| id | name   | color |
+----+--------+--------+
| 3 | banana | yellow |
| 8 | mango | yellow |
| 10 | jack   | green |
+----+--------+--------+
3 rows in set (0.00 sec)



                                                     +,
Copy a table with structure
mysql> create table fruits1 like fruits;
Query OK, 0 rows affected (0.00 sec)

mysql> create table fruits2 select * from fruits;
Query OK, 8 rows affected (0.33 sec)
Records: 8 Duplicates: 0 Warnings: 0

mysql> desc fruits2;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(5)      | NO   |     | 0       |       |
| name | varchar(25) | YES |       | NULL    |       |
| color | varchar(15) | YES |      | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)




                                                         +-
Copy a table with structure
mysql> select * from fruits2;
+----+---------+--------+
| id | name    | color |
+----+---------+--------+
| 1 | apple    | red    |
| 2 | cherry | red      |
| 3 | banana | yellow |
| 7 | grape    | black |
| 8 | mango    | yellow |
| 6 | goa      | green |
| 9 | suppota | brown |
| 10 | jack    | green |
+----+---------+--------+
8 rows in set (0.00 sec)

mysql>




                                +.
Grouping Function
mysql> select color,count(*) from fruits group by color;
+--------+----------+
| color | count(*) |
+--------+----------+
| black |         1 |
| brown |         1 |
| green |         2 |
| red    |        2 |
| yellow |        2 |
+--------+----------+
5 rows in set (0.08 sec)




                                                           /
Grouping Function
mysql> select color,count(*) as cnt from fruits group by
color order by cnt;
+--------+-----+
| color | cnt |
+--------+-----+
| black |    1 |
| brown |    1 |
| red    |   2 |
| yellow |   2 |
| green |    2 |
+--------+-----+
5 rows in set (0.00 sec)
Grouping Function
mysql> select color,count(*) as cnt from fruits group by
color order by cnt desc;
+--------+-----+
| color | cnt |
+--------+-----+
| red    |   2 |
| yellow |   2 |
| green |    2 |
| black |    1 |
| brown |    1 |
+--------+-----+
5 rows in set (0.00 sec)

mysql>




                                                           '
Altering Table
mysql> alter table fruits add rate float(3,2) default 0.0;
Query OK, 8 rows affected (0.28 sec)
Records: 8 Duplicates: 0 Warnings: 0

mysql> select * from fruits;
+----+---------+--------+------+
| id | name    | color | rate |
+----+---------+--------+------+
| 1 | apple    | red     | 0.00 |
| 2 | cherry | red       | 0.00 |
| 3 | banana | yellow | 0.00 |
| 7 | grape    | black | 0.00 |
| 8 | mango    | yellow | 0.00 |
| 6 | goa      | green | 0.00 |
| 9 | suppota | brown | 0.00 |
| 10 | jack    | green | 0.00 |
+----+---------+--------+------+
8 rows in set (0.00 sec)

Mysql>


                                                             )
Updating the Records
mysql> update fruits set rate=5 where name='apple' or
name='mango';
Query OK, 2 rows affected (0.05 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> update fruits set rate=0.5 where name in
('cherry','grape');
Query OK, 2 rows affected (0.06 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> update fruits set rate=2.25 where rate=0;
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0

mysql>




                                                        *
Updating the Records
mysql> select * from fruits;
+----+---------+--------+------+
| id | name    | color | rate |
+----+---------+--------+------+
| 1 | apple    | red    | 5.00 |
| 2 | cherry | red      | 0.50 |
| 3 | banana | yellow | 2.25 |
| 7 | grape    | black | 0.50 |
| 8 | mango    | yellow | 5.00 |
| 6 | goa      | green | 2.25 |
| 9 | suppota | brown | 2.25 |
| 10 | jack    | green | 2.25 |
+----+---------+--------+------+
8 rows in set (0.00 sec)

mysql>




                                   +
More than one table
mysql> create table purchase(
    -> fruit varchar(25), qty int(3) default 0)engine=myisam;
Query OK, 0 rows affected (0.11 sec)

mysql> load data local infile 'c:/buy.txt' into table purchase
fields terminated by ',' lines terminated by 'rn';
Query OK, 4 rows affected (0.05 sec)
Records: 4 Deleted: 0 Skipped: 0 Warnings: 0

mysql> select * from purchase;
+--------+------+
| fruit | qty |
+--------+------+
| apple |     5 |
| grape |    30 |
| goa    |    3 |
| banana |   12 |
+--------+------+
4 rows in set (0.00 sec)

mysql>
Combined Query
mysql> select a.name,a.rate,b.qty,b.qty*a.rate as amount from fruits
a, purchase b where a.name=b.fruit;
+--------+------+------+--------+
| name   | rate | qty | amount |
+--------+------+------+--------+
| apple | 5.00 |     5 | 25.00 |
| banana | 2.25 |   12 | 27.00 |
| grape | 0.50 |    30 | 15.00 |
| goa    | 2.25 |    3 |   6.75 |
+--------+------+------+--------+
4 rows in set (0.00 sec)

mysql> select sum(b.qty*a.rate) as amount from fruits a, purchase b
where a.name=b.fruit;
+--------+
| amount |
+--------+
| 73.75 |
+--------+
1 row in set (0.05 sec)

mysql>


                                                                       ,
Indexing
mysql> create index index1 on fruits(rate,color);
Query OK, 8 rows affected (0.14 sec)
Records: 8 Duplicates: 0 Warnings: 0

mysql> show keys from fruits;
+--------+------------+----------+--------------+-------------+-----------
+-----
--------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation |
Card
inality | Sub_part | Packed | Null | Index_type | Comment | Index_Comment |
+--------+------------+----------+--------------+-------------+-----------
+-----
--------+----------+--------+------+------------+---------+---------------+
| fruits |          0 | PRIMARY |             1 | id          | A         |
      8 |     NULL | NULL   |      | BTREE      |         |               |
| fruits |          1 | index1   |            1 | rate        | A         |
   NULL |     NULL | NULL   | YES | BTREE       |         |               |
| fruits |          1 | index1   |            2 | color       | A         |
   NULL |     NULL | NULL   | YES | BTREE       |         |               |
+--------+------------+----------+--------------+-------------+-----------
+-----
--------+----------+--------+------+------------+---------+---------------+
3 rows in set (0.00 sec)

mysql>

                                                                          -
Stored - Functions
mysql>select rate from lamp.fruits where fruit=’apple’;
+------+
| rate |
+------+
| 5.00 |
+------+
1 row in set (0.00 sec)

mysql> delimiter |;
mysql> create function GetFruitRate(item varchar(20))
    -> returns float
    -> deterministic
    -> begin
    -> declare rt float;
    -> select rate into rt from lamp.fruits where name=item;
    -> return rt;
    -> end|
Query OK, 0 rows affected (0.14 sec)

mysql> select GetFruitRate('banana');
+------------------------+
| GetFruitRate('banana') |
+------------------------+
|                   2.25 |
+------------------------+
1 row in set (0.00 sec)

                                                               .
Listing all the available stored functions
mysql> show function statusG
*************************** 1. row
***************************
                  Db: lamp
                Name: GetFruitRate
                Type: FUNCTION
             Definer: root@localhost
            Modified: 2008-01-25 12:27:27
             Created: 2008-01-25 12:27:27
       Security_type: DEFINER
             Comment:
character_set_client: latin1
collation_connection: latin1_swedish_ci
  Database Collation: latin1_swedish_ci
1 row in set (0.00 sec)
mysql>




                                             ,/
To view the code
mysql> show create function GetFruitRateG
*************************** 1. row
***************************
             Function: GetFruitRate
             sql_mode: STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER
      Create Function: CREATE DEFINER=`root`@`localhost`
FUNCTION `GetFruitRate`(
item varchar(20)) RETURNS float
    DETERMINISTIC
begin
declare rt float;
select rate into rt from lamp.fruits where name=item;
return rt;
end
character_set_client: latin1
collation_connection: latin1_swedish_ci
  Database Collation: latin1_swedish_ci
1 row in set (0.00 sec)

mysql>


                                                             ,
Procedures
mysql> delimiter |
mysql> create procedure ChangeFruitRate(item varchar(20),
newrate float)
    -> begin
    -> declare cnt int;
    -> select count(*) into cnt from lamp.fruits where
name=item;
    -> if cnt>0 then
    -> update lamp.fruits set rate=newrate where
name=item;
    -> select name,rate from lamp.fruits where name=item;
    -> else
    -> select concat(item, ' not available in the fruits
table') as Error;
    -> end if;
    -> end|
Query OK, 0 rows affected (0.09 sec)




                                                            ,'
Procedures
mysql> delimiter ;
mysql> call ChangeFruitRate('apple',6.50);
+-------+------+
| name | rate |
+-------+------+
| apple | 6.50 |
+-------+------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.02 sec)
mysql> select * from fruits;
+----+---------+--------+------+
| id | name    | color | rate |
+----+---------+--------+------+
| 1 | apple    | red    | 6.50 |
| 2 | cherry | red      | 0.50 |
| 3 | banana | yellow | 2.25 |
| 7 | grape    | black | 0.50 |
| 8 | mango    | yellow | 5.00 |
| 6 | goa      | green | 2.25 |
| 9 | suppota | brown | 2.25 |
| 10 | jack    | green | 2.25 |
+----+---------+--------+------+
8 rows in set (0.00 sec)

mysql>
                                             ,)
Procedures
mysql> call ChangeFruitRate('orange',6.50);
+------------------------------------------+
| Error                                    |
+------------------------------------------+
| orange not available in the fruits table |
+------------------------------------------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.02 sec)

mysql>




                                               ,*
Trigger
mysql> create table log(time datetime, task
varchar(200)engine=myisam;
Query OK, 0 rows affected (0.02 sec)

mysql> delimiter |
mysql> create trigger LogRateChange after update on fruits
    -> for each row
    -> begin
    -> insert into log values(now(),concat(new.name,' rate
changed from ', old.rate, ' to ', new.rate));
    -> end;
    -> |
Query OK, 0 rows affected (0.00 sec)

mysql> delimiter ;
mysql> update fruits set rate='7.5' where name='apple';
Query OK, 1 row affected (0.00 sec)




                                                          ,+
Trigger
mysql> select * from fruits;
+----+---------+--------+------+
| id | name    | color | rate |
+----+---------+--------+------+
| 1 | apple    | red    | 7.50 |
| 2 | cherry | red      | 0.50 |
| 3 | banana | yellow | 2.25 |
| 7 | grape    | black | 0.50 |
| 8 | mango    | yellow | 5.00 |
| 6 | goa      | green | 4.50 |
| 9 | suppota | brown | 2.25 |
| 10 | jack    | green | 2.25 |
+----+---------+--------+------+
8 rows in set (0.00 sec)

mysql> select * from log;
+---------------------+--------------------------------------+
| time                | task                                 |
+---------------------+--------------------------------------+
| 2008-01-25 14:21:38 | apple rate changed from 6.50 to 7.50 |
+---------------------+--------------------------------------+
1 row in set (0.00 sec)

mysql>



                                                                 ,
Views
mysql> create view myfruits as select name, rate from
fruits;
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
+----------------+
| Tables_in_lamp |
+----------------+
| fruits         |
| fruits1        |
| log            |
| myfruits       |
| purchase       |
+----------------+
5 rows in set (0.00 sec)




                                                        ,,
Views
mysql> select * from myfruits;
+---------+------+
| name    | rate |
+---------+------+
| apple   | 7.50 |
| cherry | 0.50 |
| banana | 2.25 |
| grape   | 0.50 |
| mango   | 5.00 |
| goa     | 4.50 |
| suppota | 2.25 |
| jack    | 2.25 |
+---------+------+
8 rows in set (0.00 sec)

mysql>




                                 ,-
User Management
Create a new user
mysql> grant all privileges on lamp.* to 'myfriend'@'localhost' identified by
‘myfriend';
Query OK, 0 rows affected (0.09 sec)




Login from another terminal as myfriend
C:>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 8
Server version: 6.0.3-alpha-community MySQL Community Server (GPL)

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql> use lamp
Database changed
mysql> update fruits set rate=5.0 where name='apple';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

Mysql>


                                                                           ,.
Revoke the update privilege from myfriend
mysql> revoke update on lamp.* from 'myfriend'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql>




If myfriend try to update again
mysql> update fruits set rate=5.0 where name='apple';
ERROR 1142 (42000): UPDATE command denied to user
'myfriend'@'localhost' for table 'fruits'
mysql>




                                                              -/
Deleting a record
mysql> select * from fruits2;
+----+---------+--------+
| id | name    | color |
+----+---------+--------+
| 1 | apple    | red    |
| 2 | cherry | red      |
| 3 | banana | yellow |
| 7 | grape    | black |
| 8 | mango    | yellow |
| 6 | goa      | green |
| 9 | suppota | brown |
| 10 | jack    | green |
+----+---------+--------+
8 rows in set (0.00 sec)

mysql> delete from fruits2 where color='green';
Query OK, 2 rows affected (0.24 sec)



                                                  -
Deleting a record
mysql> select * from fruits2;
+----+---------+--------+
| id | name    | color |
+----+---------+--------+
| 1 | apple    | red    |
| 2 | cherry | red      |
| 3 | banana | yellow |
| 7 | grape    | black |
| 8 | mango    | yellow |
| 9 | suppota | brown |
+----+---------+--------+
6 rows in set (0.00 sec)

mysql>




                                -'
Dropping a table
mysql> truncate table fruits2;
Query OK, 6 rows affected (0.28 sec)

mysql> select * from fruits2;
Empty set (0.00 sec)

mysql> drop table fruits2;
Query OK, 0 rows affected (0.16 sec)

mysql> show tables;
+----------------+
| Tables_in_lamp |
+----------------+
| fruits         |
| fruits1        |
| purchase       |
+----------------+
3 rows in set (0.06 sec)


                                       -)
Dropping a database
mysql> drop database lamp;
Query OK, 0 rows affected (0.00 sec)

mysql> select database();
+------------+
| database() |
+------------+
| NULL       |
+------------+
1 row in set (0.00 sec)

mysql>




                                       -*
Quit from mysql prompt
mysql> exit
Bye

C:>




                         -+
-

Más contenido relacionado

La actualidad más candente

The Security Risks of Web 2.0 - DEF CON 17
The Security Risks of Web 2.0 - DEF CON 17The Security Risks of Web 2.0 - DEF CON 17
The Security Risks of Web 2.0 - DEF CON 17Security Ninja
 
9t rainforest menus
9t rainforest menus9t rainforest menus
9t rainforest menusAshleigh100
 
Webinar: Online Fundraising
Webinar: Online FundraisingWebinar: Online Fundraising
Webinar: Online FundraisingifPeople
 
Get me a mobile strategy or you're fired web 2
Get me a mobile strategy or you're fired   web 2Get me a mobile strategy or you're fired   web 2
Get me a mobile strategy or you're fired web 2Jason Grigsby
 
Cysts of the jaw 10
Cysts of the jaw 10Cysts of the jaw 10
Cysts of the jaw 10Hai Trieu
 
6.Conocimiento cliente Cuenta Pagos en Linea. (Interlat Group
6.Conocimiento cliente Cuenta Pagos en Linea. (Interlat Group6.Conocimiento cliente Cuenta Pagos en Linea. (Interlat Group
6.Conocimiento cliente Cuenta Pagos en Linea. (Interlat GroupInterlat
 
DiplomadoIABMex_Equipo6
DiplomadoIABMex_Equipo6DiplomadoIABMex_Equipo6
DiplomadoIABMex_Equipo6jorgemacias23
 
Tyler Maiman's Thesis
Tyler Maiman's ThesisTyler Maiman's Thesis
Tyler Maiman's Thesisprameya
 
Varias formas de se ver uma loja Artigo para a Revista Dirigente Lojista
Varias formas de se ver uma loja Artigo para a Revista Dirigente LojistaVarias formas de se ver uma loja Artigo para a Revista Dirigente Lojista
Varias formas de se ver uma loja Artigo para a Revista Dirigente LojistaFlávio Radamarker, RDI
 
Presentazione comunità finanziaria 10nov11
Presentazione comunità finanziaria 10nov11Presentazione comunità finanziaria 10nov11
Presentazione comunità finanziaria 10nov11MondadoriGroup
 

La actualidad más candente (19)

The Security Risks of Web 2.0 - DEF CON 17
The Security Risks of Web 2.0 - DEF CON 17The Security Risks of Web 2.0 - DEF CON 17
The Security Risks of Web 2.0 - DEF CON 17
 
Rate4
Rate4Rate4
Rate4
 
9t rainforest menus
9t rainforest menus9t rainforest menus
9t rainforest menus
 
Webinar: Online Fundraising
Webinar: Online FundraisingWebinar: Online Fundraising
Webinar: Online Fundraising
 
Get me a mobile strategy or you're fired web 2
Get me a mobile strategy or you're fired   web 2Get me a mobile strategy or you're fired   web 2
Get me a mobile strategy or you're fired web 2
 
Cysts of the jaw 10
Cysts of the jaw 10Cysts of the jaw 10
Cysts of the jaw 10
 
An easy way to learn hip muscles
An easy way to learn hip musclesAn easy way to learn hip muscles
An easy way to learn hip muscles
 
Bhaarya akkato
Bhaarya akkatoBhaarya akkato
Bhaarya akkato
 
Bra
BraBra
Bra
 
6.Conocimiento cliente Cuenta Pagos en Linea. (Interlat Group
6.Conocimiento cliente Cuenta Pagos en Linea. (Interlat Group6.Conocimiento cliente Cuenta Pagos en Linea. (Interlat Group
6.Conocimiento cliente Cuenta Pagos en Linea. (Interlat Group
 
DiplomadoIABMex_Equipo6
DiplomadoIABMex_Equipo6DiplomadoIABMex_Equipo6
DiplomadoIABMex_Equipo6
 
Tyler Maiman's Thesis
Tyler Maiman's ThesisTyler Maiman's Thesis
Tyler Maiman's Thesis
 
Recetas cocina-cubana
Recetas cocina-cubanaRecetas cocina-cubana
Recetas cocina-cubana
 
Wells Fargo Outline
Wells Fargo Outline Wells Fargo Outline
Wells Fargo Outline
 
Anna bhaaryato
Anna bhaaryatoAnna bhaaryato
Anna bhaaryato
 
Varias formas de se ver uma loja Artigo para a Revista Dirigente Lojista
Varias formas de se ver uma loja Artigo para a Revista Dirigente LojistaVarias formas de se ver uma loja Artigo para a Revista Dirigente Lojista
Varias formas de se ver uma loja Artigo para a Revista Dirigente Lojista
 
Presentazione comunità finanziaria 10nov11
Presentazione comunità finanziaria 10nov11Presentazione comunità finanziaria 10nov11
Presentazione comunità finanziaria 10nov11
 
Csharp Intsight
Csharp IntsightCsharp Intsight
Csharp Intsight
 
Chinese
ChineseChinese
Chinese
 

Destacado

Rejuvenolads
RejuvenoladsRejuvenolads
Rejuvenoladsuiucqt
 
Limpeza do percurso do Corta-mato
Limpeza do percurso do Corta-matoLimpeza do percurso do Corta-mato
Limpeza do percurso do Corta-matoNunoMoreira
 
Giới thiệu chung về ChợĐiệnTử
Giới thiệu chung về ChợĐiệnTửGiới thiệu chung về ChợĐiệnTử
Giới thiệu chung về ChợĐiệnTửguestbd5f93
 
User Study Multitouch on Safari
User Study Multitouch on SafariUser Study Multitouch on Safari
User Study Multitouch on SafariDavy Debacker
 
Jak przeskoczyć przepaść, stworzyć produkt technologiczny i na nim zarobić - ...
Jak przeskoczyć przepaść, stworzyć produkt technologiczny i na nim zarobić - ...Jak przeskoczyć przepaść, stworzyć produkt technologiczny i na nim zarobić - ...
Jak przeskoczyć przepaść, stworzyć produkt technologiczny i na nim zarobić - ...Fundacja Rozwoju Branży Internetowej Netcamp
 
Paper Sloodle Mptl14ud V.1
Paper Sloodle Mptl14ud V.1Paper Sloodle Mptl14ud V.1
Paper Sloodle Mptl14ud V.1Eleonora Porta
 
Corso di video registrazione in virtual worlds
Corso di video registrazione in virtual worldsCorso di video registrazione in virtual worlds
Corso di video registrazione in virtual worldsEleonora Porta
 
West Palm Beach, FL 3/24/2005
West Palm Beach, FL 3/24/2005West Palm Beach, FL 3/24/2005
West Palm Beach, FL 3/24/2005TRIC Tools
 
The Heinz Endowments Youth Philanthropy Board Meeting
The Heinz Endowments Youth Philanthropy Board MeetingThe Heinz Endowments Youth Philanthropy Board Meeting
The Heinz Endowments Youth Philanthropy Board Meetingwaj97waj97
 
Implica't amb activitats solidàries. CEE Esperança
Implica't amb activitats solidàries. CEE EsperançaImplica't amb activitats solidàries. CEE Esperança
Implica't amb activitats solidàries. CEE EsperançaLLuelles Perera Maria del Mar
 

Destacado (20)

Rejuvenolads
RejuvenoladsRejuvenolads
Rejuvenolads
 
Limpeza do percurso do Corta-mato
Limpeza do percurso do Corta-matoLimpeza do percurso do Corta-mato
Limpeza do percurso do Corta-mato
 
Giới thiệu chung về ChợĐiệnTử
Giới thiệu chung về ChợĐiệnTửGiới thiệu chung về ChợĐiệnTử
Giới thiệu chung về ChợĐiệnTử
 
Smarter Cities czyli inteligente miasta wg IBM
Smarter Cities czyli inteligente miasta wg IBMSmarter Cities czyli inteligente miasta wg IBM
Smarter Cities czyli inteligente miasta wg IBM
 
Netcamp #8 - Startup w Londynie czyli Szuku.pl na Seedcampie
Netcamp #8 - Startup w Londynie czyli Szuku.pl na SeedcampieNetcamp #8 - Startup w Londynie czyli Szuku.pl na Seedcampie
Netcamp #8 - Startup w Londynie czyli Szuku.pl na Seedcampie
 
User Study Multitouch on Safari
User Study Multitouch on SafariUser Study Multitouch on Safari
User Study Multitouch on Safari
 
Jak przeskoczyć przepaść, stworzyć produkt technologiczny i na nim zarobić - ...
Jak przeskoczyć przepaść, stworzyć produkt technologiczny i na nim zarobić - ...Jak przeskoczyć przepaść, stworzyć produkt technologiczny i na nim zarobić - ...
Jak przeskoczyć przepaść, stworzyć produkt technologiczny i na nim zarobić - ...
 
Zmysły rozszerzone - jak wearable computing zmienia świat - Paweł Surgiel
Zmysły rozszerzone - jak wearable computing zmienia świat - Paweł SurgielZmysły rozszerzone - jak wearable computing zmienia świat - Paweł Surgiel
Zmysły rozszerzone - jak wearable computing zmienia świat - Paweł Surgiel
 
Trudności w implementacji systemów SaaS
Trudności w implementacji systemów SaaSTrudności w implementacji systemów SaaS
Trudności w implementacji systemów SaaS
 
Paper Sloodle Mptl14ud V.1
Paper Sloodle Mptl14ud V.1Paper Sloodle Mptl14ud V.1
Paper Sloodle Mptl14ud V.1
 
Corso di video registrazione in virtual worlds
Corso di video registrazione in virtual worldsCorso di video registrazione in virtual worlds
Corso di video registrazione in virtual worlds
 
West Palm Beach, FL 3/24/2005
West Palm Beach, FL 3/24/2005West Palm Beach, FL 3/24/2005
West Palm Beach, FL 3/24/2005
 
The Heinz Endowments Youth Philanthropy Board Meeting
The Heinz Endowments Youth Philanthropy Board MeetingThe Heinz Endowments Youth Philanthropy Board Meeting
The Heinz Endowments Youth Philanthropy Board Meeting
 
Implica't amb activitats solidàries. CEE Esperança
Implica't amb activitats solidàries. CEE EsperançaImplica't amb activitats solidàries. CEE Esperança
Implica't amb activitats solidàries. CEE Esperança
 
Netcamp at Cebit 2012
Netcamp at Cebit 2012Netcamp at Cebit 2012
Netcamp at Cebit 2012
 
2005 0504 Ca
2005 0504 Ca2005 0504 Ca
2005 0504 Ca
 
Robert Olejnik - Bezpieczeństwo w chmurach, czyli jak i dlaczego stworzyliśmy...
Robert Olejnik - Bezpieczeństwo w chmurach, czyli jak i dlaczego stworzyliśmy...Robert Olejnik - Bezpieczeństwo w chmurach, czyli jak i dlaczego stworzyliśmy...
Robert Olejnik - Bezpieczeństwo w chmurach, czyli jak i dlaczego stworzyliśmy...
 
Paweł Spychalski - Optymalizacja zapytań my sql
Paweł Spychalski - Optymalizacja zapytań my sqlPaweł Spychalski - Optymalizacja zapytań my sql
Paweł Spychalski - Optymalizacja zapytań my sql
 
Netcamp #1 Case Study Hip-Hop.pl
Netcamp #1 Case Study Hip-Hop.plNetcamp #1 Case Study Hip-Hop.pl
Netcamp #1 Case Study Hip-Hop.pl
 
L’ hort a l’escola bressol municipal secà
L’ hort a l’escola bressol municipal secàL’ hort a l’escola bressol municipal secà
L’ hort a l’escola bressol municipal secà
 

Similar a LAMP_TRAINING_SESSION_6

WALA Tutorial at PLDI 2010
WALA Tutorial at PLDI 2010WALA Tutorial at PLDI 2010
WALA Tutorial at PLDI 2010Julian Dolby
 
Projet Sponsoring Paris Football Club
Projet Sponsoring Paris Football ClubProjet Sponsoring Paris Football Club
Projet Sponsoring Paris Football ClubJim Totime
 
SEO - It Works Even if You Don’t Know How or Why
SEO - It Works Even if You Don’t Know How or Why SEO - It Works Even if You Don’t Know How or Why
SEO - It Works Even if You Don’t Know How or Why Wolfgang Weicht
 
¿Riesgo de quiebra en Cambre?
¿Riesgo de quiebra en Cambre?¿Riesgo de quiebra en Cambre?
¿Riesgo de quiebra en Cambre?el emboscado
 
Nearby Startup Pitch for SUU 2013 conference
Nearby Startup Pitch for SUU 2013 conferenceNearby Startup Pitch for SUU 2013 conference
Nearby Startup Pitch for SUU 2013 conferenceAdam Nemeth
 
E-Primer Your Business Online
E-Primer Your Business OnlineE-Primer Your Business Online
E-Primer Your Business Onlineguestfc9d8a
 
Bio Startup Spinoff 2010
Bio Startup Spinoff 2010Bio Startup Spinoff 2010
Bio Startup Spinoff 2010Servadio
 
Танки_в_Лунапарке: нагрузочное_тестирование_в_Яндексе
Танки_в_Лунапарке: нагрузочное_тестирование_в_ЯндексеТанки_в_Лунапарке: нагрузочное_тестирование_в_Яндексе
Танки_в_Лунапарке: нагрузочное_тестирование_в_ЯндексеYandex
 
VoCamp Seoul2009 Sparql
VoCamp Seoul2009 SparqlVoCamp Seoul2009 Sparql
VoCamp Seoul2009 Sparqlkwangsub kim
 
Biografía Miguel Hernández Pwp
Biografía Miguel Hernández   PwpBiografía Miguel Hernández   Pwp
Biografía Miguel Hernández PwpAbrilm
 
Startershandboek
StartershandboekStartershandboek
Startershandboekdijkhuizen
 
Slimmer werken aan zorgdossiers in organisaties
Slimmer werken aan zorgdossiers in organisatiesSlimmer werken aan zorgdossiers in organisaties
Slimmer werken aan zorgdossiers in organisatiesJos Arets
 

Similar a LAMP_TRAINING_SESSION_6 (20)

Ph 2
Ph 2Ph 2
Ph 2
 
Curriculo de primer año
Curriculo de primer añoCurriculo de primer año
Curriculo de primer año
 
WALA Tutorial at PLDI 2010
WALA Tutorial at PLDI 2010WALA Tutorial at PLDI 2010
WALA Tutorial at PLDI 2010
 
Projet Sponsoring Paris Football Club
Projet Sponsoring Paris Football ClubProjet Sponsoring Paris Football Club
Projet Sponsoring Paris Football Club
 
OSGi - beyond the myth
OSGi -  beyond the mythOSGi -  beyond the myth
OSGi - beyond the myth
 
Layouts
LayoutsLayouts
Layouts
 
Ph 35
Ph 35Ph 35
Ph 35
 
ESWC 2009 Lightning Talks
ESWC 2009 Lightning TalksESWC 2009 Lightning Talks
ESWC 2009 Lightning Talks
 
SEO - It Works Even if You Don’t Know How or Why
SEO - It Works Even if You Don’t Know How or Why SEO - It Works Even if You Don’t Know How or Why
SEO - It Works Even if You Don’t Know How or Why
 
OpenSSO Microsoft Interop
OpenSSO Microsoft InteropOpenSSO Microsoft Interop
OpenSSO Microsoft Interop
 
¿Riesgo de quiebra en Cambre?
¿Riesgo de quiebra en Cambre?¿Riesgo de quiebra en Cambre?
¿Riesgo de quiebra en Cambre?
 
Nearby Startup Pitch for SUU 2013 conference
Nearby Startup Pitch for SUU 2013 conferenceNearby Startup Pitch for SUU 2013 conference
Nearby Startup Pitch for SUU 2013 conference
 
E-Primer Your Business Online
E-Primer Your Business OnlineE-Primer Your Business Online
E-Primer Your Business Online
 
Bio Startup Spinoff 2010
Bio Startup Spinoff 2010Bio Startup Spinoff 2010
Bio Startup Spinoff 2010
 
Танки_в_Лунапарке: нагрузочное_тестирование_в_Яндексе
Танки_в_Лунапарке: нагрузочное_тестирование_в_ЯндексеТанки_в_Лунапарке: нагрузочное_тестирование_в_Яндексе
Танки_в_Лунапарке: нагрузочное_тестирование_в_Яндексе
 
VoCamp Seoul2009 Sparql
VoCamp Seoul2009 SparqlVoCamp Seoul2009 Sparql
VoCamp Seoul2009 Sparql
 
Mailings Sublevación de Abril
Mailings Sublevación de AbrilMailings Sublevación de Abril
Mailings Sublevación de Abril
 
Biografía Miguel Hernández Pwp
Biografía Miguel Hernández   PwpBiografía Miguel Hernández   Pwp
Biografía Miguel Hernández Pwp
 
Startershandboek
StartershandboekStartershandboek
Startershandboek
 
Slimmer werken aan zorgdossiers in organisaties
Slimmer werken aan zorgdossiers in organisatiesSlimmer werken aan zorgdossiers in organisaties
Slimmer werken aan zorgdossiers in organisaties
 

Más de umapst

LAMP_TRAINING_SESSION_8
LAMP_TRAINING_SESSION_8LAMP_TRAINING_SESSION_8
LAMP_TRAINING_SESSION_8umapst
 
LAMP_TRAINING_SESSION_7
LAMP_TRAINING_SESSION_7LAMP_TRAINING_SESSION_7
LAMP_TRAINING_SESSION_7umapst
 
LAMP_TRAINING_SESSION_5
LAMP_TRAINING_SESSION_5LAMP_TRAINING_SESSION_5
LAMP_TRAINING_SESSION_5umapst
 
LAMP_TRAINING_SESSION_4
LAMP_TRAINING_SESSION_4LAMP_TRAINING_SESSION_4
LAMP_TRAINING_SESSION_4umapst
 
LAMP_TRAINING_SESSION_3
LAMP_TRAINING_SESSION_3LAMP_TRAINING_SESSION_3
LAMP_TRAINING_SESSION_3umapst
 
LAMP_TRAINING_SESSION_2
LAMP_TRAINING_SESSION_2LAMP_TRAINING_SESSION_2
LAMP_TRAINING_SESSION_2umapst
 
LAMP_TRAINING_SESSION_1
LAMP_TRAINING_SESSION_1LAMP_TRAINING_SESSION_1
LAMP_TRAINING_SESSION_1umapst
 
LAMP_TRAINING_SESSION_0
LAMP_TRAINING_SESSION_0LAMP_TRAINING_SESSION_0
LAMP_TRAINING_SESSION_0umapst
 

Más de umapst (8)

LAMP_TRAINING_SESSION_8
LAMP_TRAINING_SESSION_8LAMP_TRAINING_SESSION_8
LAMP_TRAINING_SESSION_8
 
LAMP_TRAINING_SESSION_7
LAMP_TRAINING_SESSION_7LAMP_TRAINING_SESSION_7
LAMP_TRAINING_SESSION_7
 
LAMP_TRAINING_SESSION_5
LAMP_TRAINING_SESSION_5LAMP_TRAINING_SESSION_5
LAMP_TRAINING_SESSION_5
 
LAMP_TRAINING_SESSION_4
LAMP_TRAINING_SESSION_4LAMP_TRAINING_SESSION_4
LAMP_TRAINING_SESSION_4
 
LAMP_TRAINING_SESSION_3
LAMP_TRAINING_SESSION_3LAMP_TRAINING_SESSION_3
LAMP_TRAINING_SESSION_3
 
LAMP_TRAINING_SESSION_2
LAMP_TRAINING_SESSION_2LAMP_TRAINING_SESSION_2
LAMP_TRAINING_SESSION_2
 
LAMP_TRAINING_SESSION_1
LAMP_TRAINING_SESSION_1LAMP_TRAINING_SESSION_1
LAMP_TRAINING_SESSION_1
 
LAMP_TRAINING_SESSION_0
LAMP_TRAINING_SESSION_0LAMP_TRAINING_SESSION_0
LAMP_TRAINING_SESSION_0
 

Último

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 

Último (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

LAMP_TRAINING_SESSION_6

  • 1.
  • 2. ! quot;quot; # $ % & ( % % ( % & '
  • 3. It is a RDBMS Developed, Distributed and Supported by MySQL AB It is Open Source It is Fast, Reliable and Easy to Use It can work as Client/Server or as Embedded System. )
  • 4. Written in C and C++ Works on Many Platforms It can Handle Multiple CPUs effectively if available Provides Transactional and Non Transactional Storage Engines Very fast Thread based Memory Allocation System Supports In Memory Hash Tables Tested with Purify and Valgrind for best performance Handles Huge Databases Portable Code *
  • 5. +
  • 6. Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 6 Server version: 6.0.3-alpha-community MySQL Community Server (GPL) Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
  • 7. +--------------------+ | Database | +--------------------+ | information_schema | | dbone | | mysql | | test | +--------------------+ 4 rows in set (0.00 sec) Database changed ,
  • 8. +----+---------+--------+ | id | name | color | +----+---------+--------+ | 1 | apple | red | | 2 | cherry | red | | 3 | banana | yellow | | 7 | grape | black | | 8 | mango | yellow | | 6 | goa | green | | 9 | suppota | brown | | 10 | jack | green | +----+---------+--------+ 8 rows in set (0.00 sec) -
  • 9. +-------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+----------------+ | id | int(5) | NO | PRI | NULL | auto_increment | | name | varchar(25) | YES | | NULL | | | color | varchar(15) | YES | | NULL | | +-------+-------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec) .
  • 10. +---------+--------+ | name | color | +---------+--------+ | apple | red | | banana | yellow | | cherry | red | | goa | green | | grape | black | | jack | green | | mango | yellow | | suppota | brown | +---------+--------+ 8 rows in set (0.00 sec) /
  • 11. +----+--------+-------+ | id | name | color | +----+--------+-------+ | 1 | apple | red | | 2 | cherry | red | +----+--------+-------+ 2 rows in set (0.00 sec) +----+--------+--------+ | id | name | color | +----+--------+--------+ | 1 | apple | red | | 2 | cherry | red | | 3 | banana | yellow | | 8 | mango | yellow | +----+--------+--------+ 4 rows in set (0.00 sec)
  • 12. '
  • 13. 0$ ! ! !! ! ! !! ! ! ! quot; quot; quot; )
  • 14. 0$ ! # $ # % & ' ( ( $& ) ( ( * ( $& ) + , - ' ( # $ # % & ' ( ( $& ) ( ( * ( $& ) + , ' - & (. /0 ( # $ # % & ' ( ( $& ) + , - ' ( ( * ( $& ) + , - ' & ( 01 ' */ *
  • 15. 0$ 2222 ' ' ( ( quot;quot;quot;quot; 2222 ' ' ( ( 3 3 4 ' 4 ' 4 4 quot;quot;quot;quot; 4 quot;4 quot; , & &) 334 ' 4 ' quot; quot; quot; / ' 5 / ' / ' 5 / ' +
  • 16. 0$ ! ( ( ( ( ! , ( , ( , ( , ( ! 0 & 6' , 7 ! / 5 6' , 7
  • 17. ,
  • 18. %& quot;#$ '()*+ ,)#)(quot;+#' ! quot; # quot; $ % '% & ( ) * ) quot; + , -. $ %& - / 0 % / 1 2 % 1 -
  • 19. )3)4 6- 5 5 7 8 )- )- 6 - 9 5 -. 94 :) 5 9 - )3 ; < 2 %= <# > !3 7 7)# ?@ A < : )# ;B . - . C # 8 B $ ) 8 $ quot; ))) : 3 $ )3 ) ) .
  • 20. -. . +%quot;' D * E E D F= 2 66 * E E 66 F= 2 GH HG 0 quot; ( GH 2HG F= 2 '/
  • 21. '
  • 22. quot;,. ( #$ +quot;$ *+#)quot;-#' .) ( $ ) / * .) 0 $ .) 1 ' ) $ .) 2 (7 .) 3 ' .) ''
  • 23. quot;4 '+ $ $ *+#)quot;-#' .) ( $ ) 5 *% ( . ) 6 .8 .) 7 7 8 9. 8 . ) 99 8 .) :: / .) ')
  • 24. -&$ (); *+#)quot;-#' .) ( $ ) 55 *% ( . ) 66 .8 .) < 0: .) 9 ; : / 9< ; 0: :< / 0: =< :9 % 0: .) :<9 % // .) 9. 8 . ) '*
  • 25. quot;,+# *+#)quot;-#' .) ( $ ) > ! ! 1 $< 7 1 1 .) (7 .) % % // 5 7 % // 5 5 ? &) # ' $ > ! 1 $< 7 8 '+
  • 26. quot;,+# *+#)quot;-#' .) ( $ ) ? % &) # ' $ % 8 0,) = % 7 5 # & $ 8 0,) ? 80; 09# ? 1 &) '
  • 27. ',
  • 28. ABS(x). ABS(x). & := ! 1'23 = & := ! 1 +'23 = CEIL(x) & := ! ! 1&'+23 = & := ! ! 1 &'+23 = CONV(N,from_base,to_base) CONV(N,from_base,to_base) & := ! !4 5 617 8# #'23 => ? & := ! !4 5 617 8# -#-23 => ? '-
  • 29. MOD(N,M). MOD(N,M). & := ! 4 1)'#,23 = & := ! 4 1)/& *23 '# = 6 FLOOR(x) & := ! 9 44 1 &'+23 = & := ! 9 44 1 &'+23 = POW(X,Y) & := ! $4 : 1'#'23 = & := ! $4 : 1'# '23 = 6 '.
  • 30. ROUND(N,M) & := ! 4;5 1 &)'*#'23 = 6 & := ! 4;5 1 &)'*#+23 = 6 SQRT(x) & := ! 1*23 = & := ! 1'/23 = 6 quot; quot;quot;quot; TRUNCATE(X,D) & := ! ;5! 1&)'*#'23 = 6 & := ! ;5! 1 ''# '23 = )/
  • 31. ASCII(str). ASCII(str) & := ! ! 1< 23 '< = & := ! ! 1'23 = & := ! ! 1< =< 23 = BIN(N) & := ! 5 1 '23 =@ ? BIT_LENGTH(str) BIT_LENGTH(str) & := ! 5 18 '823 = )
  • 32. CHAR(N,... [USING charset_name]) charset_name]) & := ! !> 1,,# ' # - #, < -)# < 23 = @' A /@ & := ! !> 1,,# )#,,& 23 ,,& < )< = @' ' ' @ CONCAT() & := ! !4 5 ! 1< <<<< < # # 23 = @' A /@ & := ! !4 5 ! 1< < 5; # #< < 23 = % // CONCAT_WS(separator,str1,str2,...) & := ! !4 5 ! ?: 1<<< ##9 # << << # 5 < 23 =@ & B $ & B / % & @ & := ! !4 5 ! ?: 1<<< ##9 # <5 ; #< 5 < 23 =@ & B / % & @ )'
  • 33. ELT(N,str1,str2,str3,...) & := ! < > # 1 #< @#< @ < < @#< < < 23 =@ C @ & := ! < > # 1*#< @#< @ < < @#< < < 23 =@ @ FIELD(str,str1,str2,str3,...) & := ! 9 < > < < > # 1< @#< @#< @#< @ < < @#< < < 23 = & := ! 9 #> < < > # 1< < < @#< @#< @ < < @#< < < 23 = FIND_IN_SET(str,strlist) FIND_IN_SET(str,strlist) & := ! 9 5 ? 5? 1< # # # < %<< %# 23 = & := ! 9 5 ? 5? 17 # *+# ,# '//<7 ,# '//#)//< 23 = ))
  • 34. FORMAT(X,D) & := ! 94 1 '))'& ')*+ #*23 =@ B 6 @ & := ! 94 1 '))'& #*23 =@ B 6 ? HEX(N_or_S) HEX(N_or_S) & := ! > A1'++23 =@ > & := ! > A1< % < 23 = INSERT(str,pos,len,newstr) INSERT(str,pos,len,newstr) & := ! 5 1< # < )#*#< : < 23 = @A D $> & := ! 5 1< # < #*#< : < 23 = @A $@ )*
  • 35. INSTR(str,substr) INSTR(str,substr) & := ! 5 1< % % << < # % 23 = & := ! 5 =% < < 1< # % < 23 = LCASE(str) LCASE(str) & := ! ! 17 $ 823 => & ) > & := ! ! 18) B 5; 0 '//-< 23 =? C !? INSERT(str,pos,len,newstr) INSERT(str,pos,len,newstr) & := ! 5 1< # < )#*#< : < 23 = @A D $> & := ! 5 1< # < #*#< : < 23 = @A $@ )+
  • 36. LEFT(str,len) LEFT(str,len) & := ! 9 17 < +23 # => ? & := ! 9 1 ')*+ #)23 => ? LENGTH(str) LENGTH(str) & := ! 5 C > 17 $ 823 = & := ! 5 C > 1 ')*+ 23 = LPAD(str,pos,len,padstr) LPAD(str,pos,len,padstr) & := ! $ 17 $< ,# 23 # 8D< = >EEE/*' #> & := ! $ 17 $< '# # 8D823 = >/*@ )
  • 37. LTRIM(str) LTRIM(str) & := ! 17 823 => ? & := ! 17 $ 723 =7 $ 7 MID(str,pos,len) MID(str,pos,len) & := ! 17 $ 8# #+23 => ? & := ! 1 ')*+ # '23 )# =? ? REPEAT(str,count) REPEAT(str,count) & := ! $ 17 < )23 > # = >3 3 3 > & := ! $ 1 /#'23 => ? ),
  • 38. REVERSE(str) REVERSE(str) & := ! 6 17: 823 = > *D ? & := ! 6 1//,23 = >,8 RIGHT(str,len) RIGHT(str,len) & := ! C > 17 $ 8#)23 => ? & := ! C > 1 '///#)23 => ? RPAD(str,len,padstr) RPAD(str,len,padstr) & := ! $ 17 $ < -#7 # D823 = >/*' #EEEE> & := ! $ 1/+/#*#+/23 => ? )-
  • 39. SPACE(10) & := ! $ ! 1 /23 => ? & := ! $ ! 1 -23 = >8 TRIM(str) TRIM(str) & := ! 17 $ 823 = >/*' # ? & := ! 1 ') 23 => ? UNHEX(str) UNHEX(str) & := ! ; 5 > A17*!* * +/823 = >/*' #> & := ! ; 5 > A17*!* * +C 823 = % // ).
  • 40. ADDDATE(date,INTERVAL expr unit) ADDDATE(date,INTERVAL & := ! 17'//- / ) 8# E ' 23 => ! ? & := ! 17'//- / ) 8# E + 23 => ! ? CURDATE() & := ! !; 123 => ! ? & := ! !; 12F .3 = ! DATEDIFF(exp1, exp2) & := ! 991 ( 12# .,+ /' /+823 8 = ! & := ! 991 ( 12# .*, /- +823 8 = ! */
  • 41. MAKETIME(hr,min,sec) MAKETIME(hr,min,sec) & := ! G 1 '# +'23 */# =? 4 4 ? & := ! G 1 '# +'23 */# = % // CURTIME() & := ! !; 123 = ? 4 4 !? & := ! !; 12F)/3 = !6 TIME_TO_SEC(x) & := ! ? 4 ? !18 /H /)823 '/H = & := ! ? 4 ? !18)/H /)823 '/H = quot; *
  • 42. *'
  • 43. Single line Query mysql> select VERSION(), CURDATE() ; +-----------------------+------------+ | VERSION() | CURDATE() | +-----------------------+------------+ | 6.0.3-alpha-community | 2008-01-21 | +-----------------------+------------+ 1 row in set (0.08 sec) mysql> *)
  • 44. Multiple line Query mysql> select VERSION(); select curdate(); +-----------------------+ | VERSION() | +-----------------------+ | 6.0.3-alpha-community | +-----------------------+ 1 row in set (0.00 sec) +------------+ | curdate() | +------------+ | 2008-01-21 | +------------+ 1 row in set (0.00 sec) mysql> **
  • 45. The Delimiter (;) mysql> select USER() -> , -> CURDATE(), -> curtime(); +----------------+------------+-----------+ | USER() | CURDATE() | curtime() | +----------------+------------+-----------+ | root@localhost | 2008-01-21 | 12:18:56 | +----------------+------------+-----------+ 1 row in set (0.05 sec) mysql> Query Termination mysql> select -> USER() -> c mysql> *+
  • 46. #-. *quot;' )%@ +)%$ %& #8. ' # ' . A'B; 9 8 F $ && 6 09 D , & ) $ && 6 C 9 D , BF $ &) F : + 6 G@H- D9 D , BF $ &) F : + 6 GIH- E9 D , BF $ &) F $< $< + H- GJ 6 219 D , BF $ &) $ && F KE6 *
  • 47. Creating and Using Databases mysql> create database LAMP; Query OK, 1 row affected (0.00 sec) mysql> mysql> use LAMP; Database changed mysql> *,
  • 48. Creating Tables mysql> show tables; Empty set (0.00 sec) mysql> create table fruits( -> id int(5) auto_increment primary key, -> name varchar(25), -> color varchar(15)) engine=myisam; Query OK, 0 rows affected (0.16 sec) mysql> show tables; +----------------+ | Tables_in_lamp | +----------------+ | fruits | +----------------+ 1 row in set (0.00 sec) mysql> *-
  • 49. Structure of the Table mysql> desc fruits; +-------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+----------------+ | id | int(5) | NO | PRI | NULL | auto_increment | | name | varchar(25) | YES | | NULL | | | color | varchar(15) | YES | | NULL | | +-------+-------------+------+-----+---------+----------------+ 3 rows in set (0.05 sec) mysql> *.
  • 50. Working with Tables mysql> select * from fruits; Empty set (0.00 sec) mysql> insert into fruits(name,color) value ('apple','red'); Query OK, 1 row affected (0.00 sec) mysql> select count(*) from fruits; +----------+ | count(*) | +----------+ | 1 | +----------+ 1 row in set (0.00 sec) +/
  • 51. Working with Tables mysql> select * from fruits; +----+-------+-------+ | id | name | color | +----+-------+-------+ | 1 | apple | red | +----+-------+-------+ 1 row in set (0.00 sec) mysql> insert into fruits values ('1','orange','orange'); ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY' mysql> +
  • 52. The effects of auto increment mysql> insert into fruits(id,name,color) values (‘2’,‘cherry’,’red’); Query Ok, 1 row affected (0.00 sec) mysql> insert into fruits(name,color) values (‘banana’,’yellow’); Query Ok, 1 row affected (0.00 sec) mysql> insert into fruits(id,name,color) values (‘7’,‘grape’,’black’); Query Ok, 1 row affected (0.00 sec) mysql> insert into fruits(name,color) values (‘mango’,’yellow’); Query Ok, 1 row affected (0.00 sec) mysql> insert into fruits(id,name,color) values (‘6’,‘goa’,’green’); Query Ok, 1 row affected (0.00 sec) mysql> insert into fruits values (null,‘suppota’,’brown’); Query Ok, 1 row affected (0.00 sec) mysql> insert into fruits(name,color) values (‘jack’,’green’); Query Ok, 1 row affected (0.00 sec) +'
  • 53. The effects of auto increment (Look at the id value) mysql> select * from fruits; +----+---------+--------+ | id | name | color | +----+---------+--------+ | 1 | apple | red | | 2 | cherry | red | | 3 | banana | yellow | | 7 | grape | black | | 8 | mango | yellow | | 6 | goa | green | | 9 | suppota | brown | | 10 | jack | green | +----+---------+--------+ 8 rows in set (0.00 sec) mysql> +)
  • 54. Sorting the records mysql> select name,color from fruits order by color; +---------+--------+ | name | color | +---------+--------+ | grape | black | | suppota | brown | | goa | green | | jack | green | | apple | red | | cherry | red | | banana | yellow | | mango | yellow | +---------+--------+ 8 rows in set (0.00 sec) mysql> +*
  • 55. Selection with conditions mysql> select * from fruits where color='red'; +----+--------+-------+ | id | name | color | +----+--------+-------+ | 1 | apple | red | | 2 | cherry | red | +----+--------+-------+ 2 rows in set (0.00 sec) mysql> select * from fruits where color='red' or color='yellow'; +----+--------+--------+ | id | name | color | +----+--------+--------+ | 1 | apple | red | | 2 | cherry | red | | 3 | banana | yellow | | 8 | mango | yellow | +----+--------+--------+ 4 rows in set (0.00 sec) ++
  • 56. Selection with conditions mysql> select * from fruits -> where (color='red' or color='yellow') and length(name) > 5; +----+--------+--------+ | id | name | color | +----+--------+--------+ | 2 | cherry | red | | 3 | banana | yellow | +----+--------+--------+ 2 rows in set (0.00 sec) mysql> select * from fruits where name like '%o%'; +----+---------+--------+ | id | name | color | +----+---------+--------+ | 8 | mango | yellow | | 6 | goa | green | | 9 | suppota | brown | +----+---------+--------+ 3 rows in set (0.00 sec) +
  • 57. Selection with conditions mysql> select * from fruits where name like '%a'; +----+---------+--------+ | id | name | color | +----+---------+--------+ | 3 | banana | yellow | | 6 | goa | green | | 9 | suppota | brown | +----+---------+--------+ 3 rows in set (0.00 sec) mysql> select * from fruits where name like '_a%'; +----+--------+--------+ | id | name | color | +----+--------+--------+ | 3 | banana | yellow | | 8 | mango | yellow | | 10 | jack | green | +----+--------+--------+ 3 rows in set (0.00 sec) +,
  • 58. Copy a table with structure mysql> create table fruits1 like fruits; Query OK, 0 rows affected (0.00 sec) mysql> create table fruits2 select * from fruits; Query OK, 8 rows affected (0.33 sec) Records: 8 Duplicates: 0 Warnings: 0 mysql> desc fruits2; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int(5) | NO | | 0 | | | name | varchar(25) | YES | | NULL | | | color | varchar(15) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 3 rows in set (0.01 sec) +-
  • 59. Copy a table with structure mysql> select * from fruits2; +----+---------+--------+ | id | name | color | +----+---------+--------+ | 1 | apple | red | | 2 | cherry | red | | 3 | banana | yellow | | 7 | grape | black | | 8 | mango | yellow | | 6 | goa | green | | 9 | suppota | brown | | 10 | jack | green | +----+---------+--------+ 8 rows in set (0.00 sec) mysql> +.
  • 60. Grouping Function mysql> select color,count(*) from fruits group by color; +--------+----------+ | color | count(*) | +--------+----------+ | black | 1 | | brown | 1 | | green | 2 | | red | 2 | | yellow | 2 | +--------+----------+ 5 rows in set (0.08 sec) /
  • 61. Grouping Function mysql> select color,count(*) as cnt from fruits group by color order by cnt; +--------+-----+ | color | cnt | +--------+-----+ | black | 1 | | brown | 1 | | red | 2 | | yellow | 2 | | green | 2 | +--------+-----+ 5 rows in set (0.00 sec)
  • 62. Grouping Function mysql> select color,count(*) as cnt from fruits group by color order by cnt desc; +--------+-----+ | color | cnt | +--------+-----+ | red | 2 | | yellow | 2 | | green | 2 | | black | 1 | | brown | 1 | +--------+-----+ 5 rows in set (0.00 sec) mysql> '
  • 63. Altering Table mysql> alter table fruits add rate float(3,2) default 0.0; Query OK, 8 rows affected (0.28 sec) Records: 8 Duplicates: 0 Warnings: 0 mysql> select * from fruits; +----+---------+--------+------+ | id | name | color | rate | +----+---------+--------+------+ | 1 | apple | red | 0.00 | | 2 | cherry | red | 0.00 | | 3 | banana | yellow | 0.00 | | 7 | grape | black | 0.00 | | 8 | mango | yellow | 0.00 | | 6 | goa | green | 0.00 | | 9 | suppota | brown | 0.00 | | 10 | jack | green | 0.00 | +----+---------+--------+------+ 8 rows in set (0.00 sec) Mysql> )
  • 64. Updating the Records mysql> update fruits set rate=5 where name='apple' or name='mango'; Query OK, 2 rows affected (0.05 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> update fruits set rate=0.5 where name in ('cherry','grape'); Query OK, 2 rows affected (0.06 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> update fruits set rate=2.25 where rate=0; Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0 mysql> *
  • 65. Updating the Records mysql> select * from fruits; +----+---------+--------+------+ | id | name | color | rate | +----+---------+--------+------+ | 1 | apple | red | 5.00 | | 2 | cherry | red | 0.50 | | 3 | banana | yellow | 2.25 | | 7 | grape | black | 0.50 | | 8 | mango | yellow | 5.00 | | 6 | goa | green | 2.25 | | 9 | suppota | brown | 2.25 | | 10 | jack | green | 2.25 | +----+---------+--------+------+ 8 rows in set (0.00 sec) mysql> +
  • 66. More than one table mysql> create table purchase( -> fruit varchar(25), qty int(3) default 0)engine=myisam; Query OK, 0 rows affected (0.11 sec) mysql> load data local infile 'c:/buy.txt' into table purchase fields terminated by ',' lines terminated by 'rn'; Query OK, 4 rows affected (0.05 sec) Records: 4 Deleted: 0 Skipped: 0 Warnings: 0 mysql> select * from purchase; +--------+------+ | fruit | qty | +--------+------+ | apple | 5 | | grape | 30 | | goa | 3 | | banana | 12 | +--------+------+ 4 rows in set (0.00 sec) mysql>
  • 67. Combined Query mysql> select a.name,a.rate,b.qty,b.qty*a.rate as amount from fruits a, purchase b where a.name=b.fruit; +--------+------+------+--------+ | name | rate | qty | amount | +--------+------+------+--------+ | apple | 5.00 | 5 | 25.00 | | banana | 2.25 | 12 | 27.00 | | grape | 0.50 | 30 | 15.00 | | goa | 2.25 | 3 | 6.75 | +--------+------+------+--------+ 4 rows in set (0.00 sec) mysql> select sum(b.qty*a.rate) as amount from fruits a, purchase b where a.name=b.fruit; +--------+ | amount | +--------+ | 73.75 | +--------+ 1 row in set (0.05 sec) mysql> ,
  • 68. Indexing mysql> create index index1 on fruits(rate,color); Query OK, 8 rows affected (0.14 sec) Records: 8 Duplicates: 0 Warnings: 0 mysql> show keys from fruits; +--------+------------+----------+--------------+-------------+----------- +----- --------+----------+--------+------+------------+---------+---------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Card inality | Sub_part | Packed | Null | Index_type | Comment | Index_Comment | +--------+------------+----------+--------------+-------------+----------- +----- --------+----------+--------+------+------------+---------+---------------+ | fruits | 0 | PRIMARY | 1 | id | A | 8 | NULL | NULL | | BTREE | | | | fruits | 1 | index1 | 1 | rate | A | NULL | NULL | NULL | YES | BTREE | | | | fruits | 1 | index1 | 2 | color | A | NULL | NULL | NULL | YES | BTREE | | | +--------+------------+----------+--------------+-------------+----------- +----- --------+----------+--------+------+------------+---------+---------------+ 3 rows in set (0.00 sec) mysql> -
  • 69. Stored - Functions mysql>select rate from lamp.fruits where fruit=’apple’; +------+ | rate | +------+ | 5.00 | +------+ 1 row in set (0.00 sec) mysql> delimiter |; mysql> create function GetFruitRate(item varchar(20)) -> returns float -> deterministic -> begin -> declare rt float; -> select rate into rt from lamp.fruits where name=item; -> return rt; -> end| Query OK, 0 rows affected (0.14 sec) mysql> select GetFruitRate('banana'); +------------------------+ | GetFruitRate('banana') | +------------------------+ | 2.25 | +------------------------+ 1 row in set (0.00 sec) .
  • 70. Listing all the available stored functions mysql> show function statusG *************************** 1. row *************************** Db: lamp Name: GetFruitRate Type: FUNCTION Definer: root@localhost Modified: 2008-01-25 12:27:27 Created: 2008-01-25 12:27:27 Security_type: DEFINER Comment: character_set_client: latin1 collation_connection: latin1_swedish_ci Database Collation: latin1_swedish_ci 1 row in set (0.00 sec) mysql> ,/
  • 71. To view the code mysql> show create function GetFruitRateG *************************** 1. row *************************** Function: GetFruitRate sql_mode: STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER Create Function: CREATE DEFINER=`root`@`localhost` FUNCTION `GetFruitRate`( item varchar(20)) RETURNS float DETERMINISTIC begin declare rt float; select rate into rt from lamp.fruits where name=item; return rt; end character_set_client: latin1 collation_connection: latin1_swedish_ci Database Collation: latin1_swedish_ci 1 row in set (0.00 sec) mysql> ,
  • 72. Procedures mysql> delimiter | mysql> create procedure ChangeFruitRate(item varchar(20), newrate float) -> begin -> declare cnt int; -> select count(*) into cnt from lamp.fruits where name=item; -> if cnt>0 then -> update lamp.fruits set rate=newrate where name=item; -> select name,rate from lamp.fruits where name=item; -> else -> select concat(item, ' not available in the fruits table') as Error; -> end if; -> end| Query OK, 0 rows affected (0.09 sec) ,'
  • 73. Procedures mysql> delimiter ; mysql> call ChangeFruitRate('apple',6.50); +-------+------+ | name | rate | +-------+------+ | apple | 6.50 | +-------+------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.02 sec) mysql> select * from fruits; +----+---------+--------+------+ | id | name | color | rate | +----+---------+--------+------+ | 1 | apple | red | 6.50 | | 2 | cherry | red | 0.50 | | 3 | banana | yellow | 2.25 | | 7 | grape | black | 0.50 | | 8 | mango | yellow | 5.00 | | 6 | goa | green | 2.25 | | 9 | suppota | brown | 2.25 | | 10 | jack | green | 2.25 | +----+---------+--------+------+ 8 rows in set (0.00 sec) mysql> ,)
  • 74. Procedures mysql> call ChangeFruitRate('orange',6.50); +------------------------------------------+ | Error | +------------------------------------------+ | orange not available in the fruits table | +------------------------------------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.02 sec) mysql> ,*
  • 75. Trigger mysql> create table log(time datetime, task varchar(200)engine=myisam; Query OK, 0 rows affected (0.02 sec) mysql> delimiter | mysql> create trigger LogRateChange after update on fruits -> for each row -> begin -> insert into log values(now(),concat(new.name,' rate changed from ', old.rate, ' to ', new.rate)); -> end; -> | Query OK, 0 rows affected (0.00 sec) mysql> delimiter ; mysql> update fruits set rate='7.5' where name='apple'; Query OK, 1 row affected (0.00 sec) ,+
  • 76. Trigger mysql> select * from fruits; +----+---------+--------+------+ | id | name | color | rate | +----+---------+--------+------+ | 1 | apple | red | 7.50 | | 2 | cherry | red | 0.50 | | 3 | banana | yellow | 2.25 | | 7 | grape | black | 0.50 | | 8 | mango | yellow | 5.00 | | 6 | goa | green | 4.50 | | 9 | suppota | brown | 2.25 | | 10 | jack | green | 2.25 | +----+---------+--------+------+ 8 rows in set (0.00 sec) mysql> select * from log; +---------------------+--------------------------------------+ | time | task | +---------------------+--------------------------------------+ | 2008-01-25 14:21:38 | apple rate changed from 6.50 to 7.50 | +---------------------+--------------------------------------+ 1 row in set (0.00 sec) mysql> ,
  • 77. Views mysql> create view myfruits as select name, rate from fruits; Query OK, 0 rows affected (0.00 sec) mysql> show tables; +----------------+ | Tables_in_lamp | +----------------+ | fruits | | fruits1 | | log | | myfruits | | purchase | +----------------+ 5 rows in set (0.00 sec) ,,
  • 78. Views mysql> select * from myfruits; +---------+------+ | name | rate | +---------+------+ | apple | 7.50 | | cherry | 0.50 | | banana | 2.25 | | grape | 0.50 | | mango | 5.00 | | goa | 4.50 | | suppota | 2.25 | | jack | 2.25 | +---------+------+ 8 rows in set (0.00 sec) mysql> ,-
  • 79. User Management Create a new user mysql> grant all privileges on lamp.* to 'myfriend'@'localhost' identified by ‘myfriend'; Query OK, 0 rows affected (0.09 sec) Login from another terminal as myfriend C:>mysql -u root -p Enter password: ****** Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 8 Server version: 6.0.3-alpha-community MySQL Community Server (GPL) Type 'help;' or 'h' for help. Type 'c' to clear the buffer. mysql> use lamp Database changed mysql> update fruits set rate=5.0 where name='apple'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 Mysql> ,.
  • 80. Revoke the update privilege from myfriend mysql> revoke update on lamp.* from 'myfriend'@'localhost'; Query OK, 0 rows affected (0.00 sec) mysql> If myfriend try to update again mysql> update fruits set rate=5.0 where name='apple'; ERROR 1142 (42000): UPDATE command denied to user 'myfriend'@'localhost' for table 'fruits' mysql> -/
  • 81. Deleting a record mysql> select * from fruits2; +----+---------+--------+ | id | name | color | +----+---------+--------+ | 1 | apple | red | | 2 | cherry | red | | 3 | banana | yellow | | 7 | grape | black | | 8 | mango | yellow | | 6 | goa | green | | 9 | suppota | brown | | 10 | jack | green | +----+---------+--------+ 8 rows in set (0.00 sec) mysql> delete from fruits2 where color='green'; Query OK, 2 rows affected (0.24 sec) -
  • 82. Deleting a record mysql> select * from fruits2; +----+---------+--------+ | id | name | color | +----+---------+--------+ | 1 | apple | red | | 2 | cherry | red | | 3 | banana | yellow | | 7 | grape | black | | 8 | mango | yellow | | 9 | suppota | brown | +----+---------+--------+ 6 rows in set (0.00 sec) mysql> -'
  • 83. Dropping a table mysql> truncate table fruits2; Query OK, 6 rows affected (0.28 sec) mysql> select * from fruits2; Empty set (0.00 sec) mysql> drop table fruits2; Query OK, 0 rows affected (0.16 sec) mysql> show tables; +----------------+ | Tables_in_lamp | +----------------+ | fruits | | fruits1 | | purchase | +----------------+ 3 rows in set (0.06 sec) -)
  • 84. Dropping a database mysql> drop database lamp; Query OK, 0 rows affected (0.00 sec) mysql> select database(); +------------+ | database() | +------------+ | NULL | +------------+ 1 row in set (0.00 sec) mysql> -*
  • 85. Quit from mysql prompt mysql> exit Bye C:> -+
  • 86. -