aprenda mysql by oreilly introd

Upload: odanel-torres

Post on 07-Aug-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    1/202

    PART I

    Introduction

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    2/202

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    3/202

    CHAPTER 1

    Introduction

     

    3

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    4/202

    Why Is MySQL so Popular?

     

     

    4 | Chapter 1: Introduction

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    5/202

    Elements of MySQL and Its Environment

         mysql 

    mysqladmin 

    Elements of MySQL and Its Environment | 5

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    6/202

     

        

    The LAMP Platform

    6 | Chapter 1: Introduction

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    7/202

    Structured Query Language

     

    MySQL Software Covered in This Book

    MySQL Software Covered in This Book | 7

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    8/202

    The Book’s Web Site

    8 | Chapter 1: Introduction

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    9/202

    CHAPTER 2

    Installing MySQL

    Installation Choices and Platforms

    9

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    10/202

    Linux

    10 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    11/202

    Live CDs

     

    Windows

     

    Mac OS X

    Installation Choices and Platforms | 11

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    12/202

    So, What Should I Do?

              

     

    Using the Command-Line Interface

    12 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    13/202

    The Linux and Mac OS X Shell konsole rxvt xterm

    [adam@eden ~]$

    eden:~ adam$

      adam  (eden ~ /home/adam ~adam adam ~ adam  eden   

    $

    cd

    /tmp 

    $ cd /tmp

    Using the Command-Line Interface | 13

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    14/202

    $ cd ~

    cd 

    ls

    $ ls ~

    cd  ls 

     

    Command completion and history

    $ cd /t

    /  My\ Important\ Notes.txt bash 

    tcsh

    up  down  history 

    $ history1 cd Photos/2 lt3 find . -name "*AMES*"4 cfdisk /dev/hda5 ssh [email protected]

    ! 3  !3  Enter 

    Performing restricted operations

       

    14 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    15/202

    su - 

    [adam@eden ~]$ su -Password: the_system_root_password [root@eden ~]#

    eden:~ adam$ su -Password: the_system_root_password eden:~ root#

    root  eden

    $ # exit

    # exit$

    sudo  root sudo-s  su - sudo  sudo 

    & sudo  sudo  bg 

    Restricting access to files and directories

           

    Using the Command-Line Interface | 15

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    16/202

    adam  adam chown  username: group   adam managers

    # chown adam:managers myfile.txt

    chmod   

    $ chmod u=rw,g=r,o=r myfile.txt

    $ chmod u=rw,g=,o= myfile.txt

      

    $ chmod u=rwx,g=rwx,o=rwx mydir

    chmod 

    $ chmod 644 myfile.txt

    $ chmod 777 mydir

    chown chmod 

    --recursive  -R 

    16 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    17/202

    The Windows Command Prompt cmd 

    C:\Documents and Settings\Adam>

    \Documents and  C: 

    C:\Users\Adam>

    cd

    dir

    cd  dir 

    %HOMEPATH% 

    C:\> cd %HOMEPATH%C:\Documents and Settings\Adam>

    Command completion and history

    /f:on  /f:on  cmd 

    cd c:\p

    Using the Command-Line Interface | 17

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    18/202

    C:\> cd c:\p

    C:\ 

    "C:\ProgramFiles" C:\Program Files\MySQL  \

    doskey/history 

    C:\> doskey/historydir C:\doskey/history

    Using a Text Editor

    18 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    19/202

     

    pico gvim vim emacs joe kate gedit xedit

    apropos "text editor" 

    gvim EditPad  TextPad

      pico vim emacs

    pico 

    $ pico myfile.txt

    $ open -a TextEdit  myfile.txt

    Using a Text Editor | 19

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    20/202

    Following the Instructions in This Book localhost

    C: 

    $

    C:\>

    #

    #

      su - sudo 

    / \ mysql bin 

    $ bin/mysql

    bin\mysql 

    user  password 

    $ mysql --user=saleh --password=tomcat

    20 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    21/202

    saleh  tomcat

    --user=saleh  user=saleh 

    --user=saleh  -u saleh

    help  mysql 

    $ mysql --helpmysql Ver 14.12 Distrib 5.0.22, for pc-linux-gnu (i686) using readline 5.0Copyright (C) 2002 MySQL ABThis software comes with ABSOLUTELY NO WARRANTY. This is free software,and you are welcome to modify and redistribute it under the GPL licenseUsage: mysql [OPTIONS] [database]  -?, --help Display this help and exit....  -p, --password[=name]  Password to use when connecting to server. If password is  not given it's asked from the tty.  -u, --user=name User for login if not current user....

    -?  --help -u  --user= -p  --password= mysql 

    \

    $ mysql \  --user=saleh \  --password=tomcat

    Following the Instructions in This Book | 21

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    22/202

    Downloading and Verifying Files from the MySQL AB Web Site

    Downloading MySQL from the MySQL AB Web Site

    Verifying Package Integrity with MD5

    22 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    23/202

    MD5: 0d2a3b39e7bb4109b2f7b451b7768f34

    md5sum 

    $ md5sum  mysql-standard-5.0.22-linux-i686.tar.gz0eaa7a8ec18699ce550db1713a27cda3 mysql-standard-5.0.22-linux-i686.tar.gz

      ...

    Downloading and Verifying Files from the MySQL AB Web Site | 23

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    24/202

    md5 

    $ md5  mysql-standard-5.0.22-osx10.4-i686.dmgMD5(mysql-standard-5.0.22-osx10.4-i686.dmg) =  b7d7f0878503db504e1eaed5d2518f4e

    24 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    25/202

    Installing Under Linux

    rpm 

    Installing Under Linux | 25

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    26/202

    apt-get 

    Installing MySQL on Linux Using RPM Packages from MySQL AB

     

    su - 

    $ su -#

    26 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    27/202

    adam

    # cd ~adam

    Desktop  adam

    # cd ~adam/Desktop

    # rpm --upgrade --verbose --hash \  MySQL-server-5.0.22-0.i386.rpm MySQL-client-5.0.22-0.i386.rpm 

    Installing MySQL on Linux Using a gzipped Tar Archive from MySQL AB  

    tar  gzip        

    $ tar --gunzip --extract --file mysql-standard-5.0.22-linux-i686.tar.gz

    gunzip  gunzip 

      gunzip 

    $ tar --extract --file mysql-standard-5.0.22-linux-i686.tar.gz

    Installing Under Linux | 27

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    28/202

       

    # mv mysql-standard-5.0.22-linux-i686 /usr/local/

    /usr/local/mysql 

    # ln --symbolic /usr/local/mysql-standard-5.0.22-linux-i686 /usr/local/mysql

    /usr/local/mysql /usr/local/mysql 

    ~/mysql 

    $ ln --symbolic ~/mysql-standard-5.0.22-linux-i686 ~/mysql

    ~/mysql   

    Installing MySQL on Linux by Compiling the Source Code from MySQL AB

     

    $ tar --gunzip --extract --file mysql-5.0.22.tar.gz

    $ cd mysql-5.0.22

    configure 

    28 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    29/202

         

      configure 

    $ ./configure --prefix=/usr/local/mysql-5.0.22

    make 

    $ make

    make  make  make make gmake 

     

    $ make install

    $ su -

    make install 

    # make install

    /usr/local/mysql     

    # ln --symbolic /usr/local/mysql-5.0.22 /usr/local/mysql

    /usr/local/mysql      ~/mysql   

    Installing Under Linux | 29

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    30/202

    $ ln --symbolic ~/mysql-5.0.22 ~/mysql

    ~/mysql

    $./configure \  --prefix=/home/adam/mysql \

      --localstatedir=/home/adam/mysql/data \  --with-unix-socket-path=/home/adam/mysql/mysql.sock \  --with-tcp-port=53306

    Installing MySQL, Apache, PHP, and Perl on Linux Using DistributionPackages

    Installation on Red Hat and Fedora Core

     

    30 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    31/202

    rpm   

    $ rpm --query --whatprovides mysql php php-mysqlmysql-5.0.22-1.FC5.1mysql-server-5.0.22-1.FC5.1httpd-2.2.0-5.1.2

    php-5.1.4-1php-mysql-5.1.4-1

    no package provides php

    Installing Under Linux | 31

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    32/202

    # pirut

    32 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    33/202

     

     

    su -

    # system-config-packages

    Installing Under Linux | 33

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    34/202

    yum yum  su -  /etc/yum.conf 

    # wget http://www.fedorafaq.org/samples/yum.conf# /bin/mv /etc/yum.conf /etc/yum.conf.bak# /bin/mv yum.conf /etc

    yum 

    # rpm --upgrade --verbose --hash http://www.fedorafaq.org/yumRetrieving http://www.fedorafaq.org/yumPreparing... ########################################### [100%]1:yum-fedorafaq ########################################### [100%]

    yum

    # yum update mysql mysql-server httpd php php-mysql[root@saiedpc ~]# yum update mysql mysql-server httpd php php-mysql...

    Could not find update match for phpCould not find update match for php-mysqlCould not find update match for mysql-serverCould not find update match for mysqlResolving Dependencies

    ...

    =============================================================================Package Arch Version Repository Size=============================================================================Updating:httpd i386 2.2.2-1.2 updates 1.1 MUpdating for dependencies:httpd-manual i386 2.2.2-1.2 updates 846 kmod_ssl i386 1:2.2.2-1.2 updates 99 k

    Transaction Summary=============================================================================Install 0 Package(s)Update 3 Package(s)Remove 0 Package(s)Total download size: 2.0 MIs this ok [y/N]: yDownloading Packages:(1/3): mod_ssl-2.2.2-1.2. 100% |=========================| 99 kB 00:14

    34 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    35/202

    (2/3): httpd-2.2.2-1.2.i3 100% |=========================| 1.1 MB 03:14(3/3): httpd-manual-2.2.2 100% |=========================| 846 kB 02:40Running Transaction TestFinished Transaction TestTransaction Test SucceededRunning TransactionUpdating : httpd ######################### [1/6]Updating : mod_ssl ######################### [2/6]Updating : httpd-manual ######################### [3/6]Cleanup : mod_ssl ######################### [4/6]Cleanup : httpd ######################### [5/6]Cleanup : httpd-manual ######################### [6/6]

    Updated: httpd.i386 0:2.2.2-1.2Dependency Updated: httpd-manual.i386 0:2.2.2-1.2 mod_ssl.i386 1:2.2.2-1.2

    Complete! Complete  yum  Could not find updatematch for  yum

      mysql su -

    # rpm --upgrade --verbose --hash \   mysql-server-5.0.22-2.1.i386.rpm \  mysql-5.0.22-2.1.i386.rpm \  httpd-2.2.2-7.i386.rpm \  php-5.1.4-8.1.i386.rpm 

    Installation on Mandriva

    $ rpm --query --whatprovides mysql mysql-client apache php php-mysqlMySQL-5.0.23-1mdv2007.0MySQL-client-5.0.23-1mdv2007.0apache-mpm-prefork-2.2.3-1mdv2007.0apache-mod_php-5.1.4-1mdk

    Installing Under Linux | 35

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    36/202

    php-cli-5.1.4-6mdv2007.0php-mysql-5.1.4-3mdv2007.0

    no package provides php

    su -

    # rpmdrake

    urpmi 

    36 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    37/202

    urpmi  urpmi  urpmi 

    # urpmi.update -a

    urpmi package_name 

    $ urpmi mysql mysql-client apache php php-mysqlOne of the following packages is needed: 1- MySQL-5.0.23-1mdv2007.0.i586 : MySQL: a very fast and reliable SQL database  engine (to install) 2- MySQL-Max-5.0.23-1mdv2007.0.i586 : MySQL - server with extended functionality  (to install) 3- MySQL-NDB-4.1.12-4.3.20060mdk.i586 : MySQL - server with Berkeley DB, Innodb  and NDB Cluster support (to install)

    What is your choice? (1-3) 1To satisfy dependencies, the following packages are going to be installed:MySQL-5.0.23-1mdv2007.0.i586MySQL-client-5.0.23-1mdv2007.0.i586MySQL-common-5.0.23-1mdv2007.0.i586apache-mod_php-5.1.4-2mdv2007.0.i586libmysql15-5.0.23-1mdv2007.0.i586perl-DBD-mysql-3.0006-1mdv2007.0.i586php-mysql-5.1.4-3mdv2007.0.i586Proceed with the installation of the 7 packages? (39 MB) (Y/n) Y

      ftp://somehost.net/somedir/libmysql15-5.0.23-1mdv2007.0.i586.rpm  ftp://somehost.net/somedir/perl-DBD-mysql-3.0006-1mdv2007.0.i586.rpm  ftp://somehost.net/somedir/MySQL-common-5.0.23-1mdv2007.0.i586.rpm  ftp://somehost.net/somedir/MySQL-client-5.0.23-1mdv2007.0.i586.rpm

      ftp://somehost.net/somedir/MySQL-5.0.23-1mdv2007.0.i586.rpm  ftp://somehost.net/somedir/apache-mod_php-5.1.4-2mdv2007.0.i586.rpminstalling  libmysql15-5.0.23-1mdv2007.0.i586.rpm  MySQL-client-5.0.23-1mdv2007.0.i586.rpm  MySQL-common-5.0.23-1mdv2007.0.i586.rpm  perl-DBD-mysql-3.0006-1mdv2007.0.i586.rpm  MySQL-5.0.23-1mdv2007.0.i586.rpm  apache-mod_php-5.1.4-2mdv2007.0.i586.rpm

    Installing Under Linux | 37

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    38/202

      php-mysql-5.1.4-3mdv2007.0.i586.rpmfrom /var/cache/urpmi/rpmsPreparing... ######...######  1/7: libmysql15 ######...######  2/7: MySQL-client ######...######  3/7: perl-DBD-mysql ######...######

    38 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    39/202

      4/7: MySQL-common ######...######  5/7: MySQL ######...######  6/7: apache-mod_php ######...######  7/7: php-mysql ######...######----------------------------------------------------------------------

    More information on package MySQL-5.0.23-1mdv2007.0.i586

    The initscript used to start mysql has been reverted to use the one shipped byMySQL AB. This means the following changes:

     * The MYSQLD_OPTIONS="--skip-networking" option in the /etc/sysconfig/mysqld  file has been removed, this is now set in the /etc/my.cnf file.

     * The MySQL Instance Manager is used by default, set use_mysqld_safe="1" in

      the /etc/sysconfig/mysqld file to use the old mysqld_safe script.

    The extra MySQL-NDB server package has been merged into the MySQL-Max packageand ndb related pieces has been split into different sub packages as done byMySQL AB. The MySQL libraries and the MySQL-common sub package uses theMySQL-Max build so that no functionality required by for example the NDB partsare lost.

    The MySQL-common package now ships with a default /etc/my.cnf file that isbased on the my-medium.cnf file that comes with the source code. The/etc/my.cnf file is constructed at build time of this package.

    To connect to the Instance Manager you need to pass the correct command lineoptions like in the following examples:

      * mysql -u root --password=my_password --port=2273 --protocol=TCP

      * mysql -u root --password=my_password  --socket=/var/lib/mysql/mysqlmanager.sock

    Please note you also need to add a user in the /etc/mysqlmanager.passwd fileand make sure the file is owned by the user under which the Instance Managerservice is running under.

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

    urpmi 

    urpmi   mysql su -

    # rpm --upgrade --verbose --hash \   MySQL-5.0.23-1mdv2007.0.i586.rpm \  MySQL-client-5.0.23-1mdv2007.0.i586.rpm \

    Installing Under Linux | 39

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    40/202

      MySQL-common-5.0.23-1mdv2007.0.i586.rpm \  apache-mod_php-5.1.4-2mdv2007.0.i586.rpm \  libmysql15-5.0.23-1mdv2007.0.i586.rpm \  perl-DBD-mysql-3.0006-1mdv2007.0.i586.rpm \  php-mysql-5.1.4-3mdv2007.0.i586.rpm 

    Installing under Debian-based systems

     

    dpkg --list  dpkg

    $ dpkg --list mysql-common mysql-server mysql-client apache2 php5No packages found matching mysql-client.No packages found matching apache2.No packages found matching php5.Desired=Unknown/Install/Remove/Purge/Hold| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)||/ Name Version Description+++-============-===============-====================================================ii mysql-common 5.0.21-3ubuntu1 mysql database common files (e.g. /etc/mysql/my.cnf)un mysql-server (no description available)

    php4  php5

    su - apt-get install # apt-get --verbose-versions install mysql-common mysql-server mysql-client apache2 php5Reading package lists... DoneBuilding dependency tree... Donemysql-common is already the newest version.The following extra packages will be installed:apache2-common (2.0.55-4ubuntu2)apache2-mpm-prefork (2.0.55-4ubuntu2)apache2-utils (2.0.55-4ubuntu2)libapache2-mod-php5 (5.1.2-1ubuntu3)libapr0 (2.0.55-4ubuntu2)libdbd-mysql-perl (3.0002-2build1)libdbi-perl (1.50-1)libnet-daemon-perl (0.38-1)libplrpc-perl (0.2017-1)

    mysql-client-5.0 (5.0.21-3ubuntu1)mysql-server-5.0 (5.0.21-3ubuntu1)php5-common (5.1.2-1ubuntu3)ssl-cert (1.0.13)Suggested packages:apache2-doc (2.0.55-4ubuntu2)lynx (2.8.5-2ubuntu1)www-browser ()php-pear (5.1.2-1ubuntu3)

    40 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    41/202

    dbishell ()libcompress-zlib-perl (1.41-1)Recommended packages:mailx (8.1.2-0.20050715cvs-1ubuntu1)The following NEW packages will be installed:apache2 (2.0.55-4ubuntu2)apache2-common (2.0.55-4ubuntu2)apache2-mpm-prefork (2.0.55-4ubuntu2)apache2-utils (2.0.55-4ubuntu2)libapache2-mod-php5 (5.1.2-1ubuntu3)libapr0 (2.0.55-4ubuntu2)libdbd-mysql-perl (3.0002-2build1)libdbi-perl (1.50-1)libnet-daemon-perl (0.38-1)libplrpc-perl (0.2017-1)

    mysql-client (5.0.21-3ubuntu1)mysql-client-5.0 (5.0.21-3ubuntu1)mysql-server (5.0.21-3ubuntu1)mysql-server-5.0 (5.0.21-3ubuntu1)php5 (5.1.2-1ubuntu3)php5-common (5.1.2-1ubuntu3)ssl-cert (1.0.13)0 upgraded, 17 newly installed, 0 to remove and 0 not upgraded.Need to get 31.9MB/32.2MB of archives.After unpacking 75.8MB of additional disk space will be used.Do you want to continue [Y/n]? Y...

    --verbose-versions  Y 

    apt-get su - dpkg --install 

    # dpkg --install \   mysql-common_5.0.22-4_all.deb \  mysql-server_5.0.22-4_all.deb \  mysql-client-5.0_5.0.22-4_i386.deb \  libmysqlclient15off_5.0.22-4_i386.deb

    apt-get   

    Installing Under Linux | 41

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    42/202

    Uninstalling MySQL rpm --upgrade urpmi yum update apt-get install  su - 

        

    rpm --erase  rpm --query --all  grep --ignore-case 

    $ rpm --query --all | grep --ignore-case mysqlperl-DBD-mysql-3.0004-1mdv2007.0MySQL-5.0.23-1mdv2007.0libmysql15-5.0.23-1mdv2007.0MySQL-client-5.0.23-1mdv2007.0php-mysql-5.1.4-3mdv2007.0MySQL-common-5.0.23-1mdv2007.0

      rpm  --erase 

    # rpm --erase \   perl-DBD-mysql-3.0004-1mdv2007.0 \  MySQL-5.0.23-1mdv2007.0 \  libmysql15-5.0.23-1mdv2007.0 \  MySQL-client-5.0.23-1mdv2007.0 \  php-mysql-5.1.4-3mdv2007.0 \  MySQL-common-5.0.23-1mdv2007.0

    xargs 

    # rpm --query --all | grep --ignore-case mysql | xargs rpm --erasewarning: /etc/my.cnf saved as /etc/my.cnf.rpmsave

    #

    yum yum remove 

    # yum remove mysql[root@saiedpc yum.repos.d]# yum remove mysql...

    Dependencies Resolved

    42 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    43/202

    ============================================================================= Package Arch Version Repository Size=============================================================================Removing: mysql i386 5.0.22-1.FC5.1 installed 5.5 MRemoving for dependencies: MySQL-python i386 1.2.0-3.2.2 installed 2.3 M libdbi-dbd-mysql i386 0.8.1a-1.2.1 installed 37 k mysql-connector-odbc i386 3.51.12-1.2.1 installed 387 k mysql-server i386 5.0.22-1.FC5.1 installed 22 M perl-Class-DBI-mysql noarch 1.00-1.fc5 installed 38 k perl-DBD-MySQL i386 3.0004-1.FC5 installed 324 k php-mysql i386 5.1.4-1 installed 176 k

    Transaction Summary

    =============================================================================Install 0 Package(s)Update 0 Package(s)Remove 8 Package(s)Is this ok [y/N]: yDownloading Packages:Running Transaction TestFinished Transaction TestTransaction Test SucceededRunning Transaction  Removing : mysql-connector-odbc ######...###### [1/8]  Removing : perl-Class-DBI-mysql ######...###### [2/8]  Removing : perl-DBD-MySQL ######...###### [3/8]  Removing : php-mysql ######...###### [4/8]  Removing : mysql ######...###### [5/8]  Removing : libdbi-dbd-mysql ######...###### [6/8]

      Removing : MySQL-python ######...###### [7/8]warning: /var/log/mysqld.log saved as /var/log/mysqld.log.rpmsave  Removing : mysql-server ######...###### [8/8]

    Removed: mysql.i386 0:5.0.22-1.FC5.1Dependency Removed:  MySQL-python.i386 0:1.2.0-3.2.2  libdbi-dbd-mysql.i386 0:0.8.1a-1.2.1  mysql-connector-odbc.i386 0:3.51.12-1.2.1  mysql-server.i386 0:5.0.22-1.FC5.1  perl-Class-DBI-mysql.noarch 0:1.00-1.fc5  perl-DBD-MySQL.i386 0:3.0004-1.FC5  php-mysql.i386 0:5.1.4-1Complete!

    apt-get remove 

    # apt-get remove mysql-server mysql-clientReading package lists... DoneBuilding dependency tree... DoneThe following packages will be REMOVED:  mysql-client mysql-server0 upgraded, 0 newly installed, 2 to remove and 1 not upgraded.Need to get 0B of archives.

    Installing Under Linux | 43

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    44/202

    After unpacking 31.3MB disk space will be freed.Do you want to continue [Y/n]? Y(Reading database ... 103699 files and directories currently installed.)Removing mysql-client ...Removing mysql-server ...

    # dpkg --search "*mysql*" | cut --fields=1 --delimiter=":" | sort --unique

    Installing MySQL, Apache, PHP, and Perl on Linux Using the XAMPPIntegrated Package

    $ su -

     

    # mkdir --parents /opt

    --parents 

    # cd /opt

    # tar --gunzip --extract --file ~adam/xampp-linux-1.5.3a.tar.gz

    adam ~adam

    # /opt/lampp/lampp startStarting XAMPP for Linux 1.5.3a...XAMPP: Starting Apache with SSL (and PHP5)...XAMPP: Starting MySQL...XAMPP: Starting ProFTPD...XAMPP for Linux started.

     

    # /opt/lampp/lampp securityXAMPP: Quick security check...XAMPP: Your XAMPP pages are NOT secured by a password.XAMPP: Do you want to set a password? [yes] nXAMPP: MySQL is accessible via network.

    44 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    45/202

    XAMPP: Normally that's not recommended. Do you want me to turn it off? [yes] yXAMPP: Turned off.XAMPP: Stopping MySQL...XAMPP: Starting MySQL...XAMPP: The MySQL/phpMyAdmin user pma has no password set!!!XAMPP: Do you want to set a password? [yes] yXAMPP: Password:XAMPP: Password (again):XAMPP: Setting new MySQL pma password.XAMPP: Setting phpMyAdmin's pma password to the new one.XAMPP: MySQL has no root password set!!!XAMPP: Do you want to set a password? [yes] yXAMPP: Write the password somewhere down to make sure you won't forget it!!!XAMPP: Password:XAMPP: Password (again):

    XAMPP: Setting new MySQL root password.XAMPP: Change phpMyAdmin's authentication method.XAMPP: The FTP password is still set to 'lampp'.XAMPP: Do you want to change the password? [yes] yXAMPP: Password:XAMPP: Password (again):XAMPP: Reload ProFTPD...XAMPP: Done.

    register_globals    

       register_globals = On On  Off

    # /opt/lampp/lampp stopStopping XAMPP for Linux 1.5.3a...XAMPP: Stopping Apache with SSL...XAMPP: Stopping MySQL...XAMPP: Stopping ProFTPD...XAMPP stopped.

      nobody root 

    Configuring a Newly Installed Server root 

    Installing Under Linux | 45

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    46/202

    root 

    Configuring a server installed using RPM or Debian packages

                 

         

    ls 

    $ ls /etc/init.d/mysql*/etc/init.d/mysql

    mysql mysql mysqld  mysql 

    # /etc/init.d/ mysql start

    root 

    $ mysqladmin --user=root password the_new_mysql_root_password 

    # /etc/init.d/ mysql stop

    Configuring a system-wide server installed from tarball or source

    su -  mysql 

    # groupadd mysql

    46 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    47/202

    mysql  mysql 

    # useradd --gid mysql mysql

      

    # cd  /usr/local/mysql

    mysql mysql_install_db   

    # scripts/mysql_install_db --user=mysql

    root  mysql 

    # chown --recursive root:mysql .

    mysql 

    # chown --recursive mysql:mysql data

    chown 

    mysql  mysqld_safe  bin 

    # bin/mysqld_safe --user=mysql &

    root 

    $ bin/mysqladmin --user=root password the_new_mysql_root_password 

    $ bin/mysqladmin --user=root --password=the_mysql_root_password  shutdown

    root  root  root  mysqladmin

        

    $ support-files/mysql.server start

    Installing Under Linux | 47

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    48/202

    $ support-files/mysql.server stop

           

    # cp support-files/mysql.server /etc/init.d/mysql

    # /etc/init.d/mysql start

    # /etc/init.d/mysql stop

    Configuring a local server

    mysql

    $ cd ~/mysql

       

    $ scripts/mysql_install_db

    datadir 

    $ mysql_install_db datadir= /home/adam/MySQL_Data

    adam

    $ chown --recursive adam:adam  ~/mysql chown 

     

    48 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    49/202

        

    $ bin/mysqld_safe --port=57777 --socket=~/mysql/data/mysql.sock &

    mysqld_safe  

    $ ~/mysql/bin/mysqld_safe \  --port=57777 \  --socket=~/mysql/data/mysql.sock \  --datadir=~/mysql/data &

    $ bin/mysqladmin \  --port=57777 \  --socket=~/mysql/data/mysql.sock \  --user=root \  password the_new_mysql_root_password 

    mysqladmin shutdown 

    $ bin/mysqladmin \  --port=57777 \  --socket=~/mysql/data/mysql.sock \  --user=root \  --password=the_mysql_root_password  \  shutdown

    Configuring MySQL for automatic start

    Installing Under Linux | 49

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    50/202

          ls 

    $ ls /etc/init.d/mysql*/etc/init.d/mysql

    mysql mysqld  mysql 

     

    runlevel   

    $ /sbin/runlevelN 5

       

    $ ls /etc/rc*.d/*mysql*/etc/rc0.d/K90mysql /etc/rc2.d/S11mysql /etc/rc4.d/S11mysql /etc/rc6.d/K90mysql/etc/rc1.d/K90mysql /etc/rc3.d/S11mysql /etc/rc5.d/S11mysql

    chkconfig--list 

    # chkconfig --list mysqlmysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off

    runlevel 

    system-config-services 

    50 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    51/202

    drakxservices 

    # chkconfig --level 35  mysql on

    # chkconfig --level 35  mysql off

    update-rc.d 

    # update-rc.d  mysql defaultsAdding system startup for /etc/init.d/mysql .../etc/rc0.d/K20mysql -> ../init.d/mysql/etc/rc1.d/K20mysql -> ../init.d/mysql/etc/rc6.d/K20mysql -> ../init.d/mysql/etc/rc2.d/S20mysql -> ../init.d/mysql/etc/rc3.d/S20mysql -> ../init.d/mysql/etc/rc4.d/S20mysql -> ../init.d/mysql/etc/rc5.d/S20mysql -> ../init.d/mysql

    # update-rc.d -f  mysql removeupdate-rc.d: /etc/init.d/mysql exists during rc.d purge (continuing)

    Removing any system startup links for /etc/init.d/mysql .../etc/rc0.d/K20mysql/etc/rc1.d/K20mysql/etc/rc2.d/S20mysql/etc/rc3.d/S20mysql/etc/rc4.d/S20mysql/etc/rc5.d/S20mysql/etc/rc6.d/K20mysql

    httpd  apache2  mysql 

    Installing Under Windows

    Installing Under Windows | 51

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    52/202

    Installing Only MySQL Using Packages from MySQL AB

    Windows installation using the installer

      

     

    52 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    53/202

    Starting and stopping MySQL as a service

    Installing Under Windows | 53

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    54/202

    C:\> net start mysql

    C:\> net stop mysql

    54 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    55/202

    C:\> cd "C:\Program Files\MySQL\MySQL Server 5.0"

    mysqladmin 

    C:\Program Files\MySQL\MySQL Server 5.0> bin\mysqladmin \  --user=root \  --password=the_mysql_root_password  \  shutdown

    Starting and stopping MySQL from the command line

     

    C:\> cd C:\Program Files\MySQL\MySQL Server 5.0\

    C:\Program Files\MySQL\MySQL Server 5.0> bin\mysqld-nt

     

    no-defaults

    C:\Program Files\MySQL\MySQL Server 5.0> bin\mysqld-nt --no-defaults

    C:\> cd C:\Program Files\MySQL\MySQL Server 5.0\

    shutdown 

    Installing Under Windows | 55

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    56/202

    C:\Program Files\MySQL\MySQL Server 5.0> bin\mysqladmin \  --user=root \  --password=the_mysql_root_password  \  shutdown

    Installation with the “no-install” .zip Archive

     

       

     

    C:\ 

    C:\> cd C:\mysql-5.0.22-win32

    C:\mysql-5.0.22-win32> bin\mysqld-nt

    56 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    57/202

    mysqld-nt  mysqld-nt.exe no-defaults

    C:\mysql-5.0.22-win32>bin\mysql-nt --no-defaults

    C:\> cd C:\mysql-5.0.22-win32

    Installing Under Windows | 57

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    58/202

    C:\mysql-5.0.22-win32> bin\mysqladmin --user=root \  password the_new_mysql_root_password 

    shutdown 

    C:\mysql-5.0.22-win32> bin\mysqladmin --user=root \  --password=the_mysql_root_password shutdown

    mysqladmin  "new root password" 

    58 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    59/202

    Installing MySQL, Apache, PHP, and Perl on Windows Using the XAMPPIntegrated Package

       

       

    Installing Under Windows | 59

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    60/202

         

    C:\> cd C:\Program Files\xampp\mysql

    mysqladmin  bin 

    C:\Program Files\xampp\mysql> bin\mysqladmin \  --user=root \  password the_new_mysql_root_password 

    60 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    61/202

     

    register_globals 

        register_globals = On On Off

    Installing Under Mac OS X

    XAMPP 

    sudo 

    Installing only MySQL Using the Installer from MySQL AB

     

         /usr/local/mysql     /usr/local/mysql

    Installing Under Mac OS X | 61

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    62/202

    Configuring the installed server mysql 

    mysql  mysql 

    grep  mysql          

    $ grep mysql /etc/passwd /etc/group/etc/passwd:mysql:*:74:74:MySQL Server:/var/empty:/usr/bin/false/etc/group:mysql:*:74:

    62 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    63/202

    mysql 

    mysql  /  

    $ sudo niutil -create / /users/mysql

    $ sudo niutil -createprop / /users/mysql home /var/empty$ sudo niutil -createprop / /users/mysql shell /usr/bin/false

    mysql

    $ sudo niutil -create / /groups/mysql

    gid mysql  uid mysql  mysql 

     

    Installing Under Mac OS X | 63

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    64/202

    $ sudo niutil -createprop / /groups/mysql gid 74$ sudo niutil -createprop / /users/mysql uid 74

    mysql  mysql 

    $ sudo niutil -createprop / /users/mysql gid 74

    $ cd /usr/local/mysql

    mysql_install_db  scripts  user  mysql 

    $ sudo scripts/mysql_install_db --user=mysql

    64 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    65/202

    root  mysql 

    $ sudo chown -RL root:mysql /usr/local/mysql

    -RL  chown  R /usr/local/mysql  L mysql 

    $ sudo chown -RL mysql:mysql /usr/local/mysql/data

    mysql_install_db  user=mysql 

     

      

    $ sudo /usr/local/mysql/support-files/mysql.server start

    Installing Under Mac OS X | 65

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    66/202

    $ sudo /usr/local/mysql/support-files/mysql.server stop

     

    $ sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

    $ sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

    mysqld_safe  mysqladmin 

    mysql  $ sudo /usr/local/mysql/bin/mysqld_safe --user=mysql

    bg 

    $ /usr/local/mysql/bin/mysqladmin --user=root \  --password=the_mysql_root_password shutdown

    root $ sudo /usr/local/mysql/bin/mysqladmin --user=root password \  the_new_mysql_root_password 

    mysqladmin

    $ /usr/local/mysql/bin/mysqladmin --user=root \  --password=the_mysql_root_password shutdown

    Installing Only MySQL Using the no-installer Package from MySQL AB

     

    66 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    67/202

       tar 

    $ cd

    $ tar --extract --file ~/Desktop/mysql-standard-5.0.22-osx10.4-i686.tar 

      gunzip 

    $ tar --gunzip --extract --file \  ~/Desktop/mysql-standard-5.0.22-osx10.4-i686.tar.gz

    mv 

    $ mv ~/Desktop/mysql-standard-5.0.22-osx10.4-i686 ~ 

    ~/mysql

    $ ln -s ~/Desktop/mysql-standard-5.0.22-osx10.4-i686  ~/mysql

    $ cd ~/mysql

       

    $ scripts/mysql_install_db

    $ bin/mysqld_safe &

    root 

    $ bin/mysqladmin --user=root password the_new_mysql_root_password 

    $ bin/mysqladmin --user=root --password=the_mysql_root_password  shutdown

    Installing Under Mac OS X | 67

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    68/202

    Installing MySQL, Apache, PHP, and Perl on Mac OS X Using the XAMPPIntegrated Package

       

      Ctrl 

            

     

    $ sudo /Applications/xampp/xamppfiles/mampp start

    $ sudo /Applications/xampp/xamppfiles/mampp security

    register_globals    

       register_globals = On On  Off

    $ sudo /Applications/xampp/xamppfiles/bin/mysqladmin \  --user root \  password the_new_mysql_root_password 

    68 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    69/202

    $ sudo /Applications/xampp/xamppfiles/mampp stop

    $ sudo /Applications/xampp/xamppfiles/bin/mysqld_safe

    bg 

    $ sudo /Applications/xampp/xamppfiles/bin/mysqladmin \  --user root \  --password=the_mysql_root_password  \  shutdown

    Using a MySQL Installation Provided by an ISP

    ssh  telnet 

    Upgrading an Existing MySQL Server

    Upgrading an Existing MySQL Server | 69

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    70/202

     

            SELECT 

    old-passwords 

    70 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    71/202

     

     

    Should I Upgrade to MySQL 5.1?

     

    How to Upgrade         

    Upgrading an Existing MySQL Server | 71

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    72/202

    Steps to Upgrade an Existing MySQL Server

       

    $ cd /usr/local/mysql

     

    $ cd ~/mysql

    MySQL  

    C:\> cd C:\Program Files\MySQL\MySQL Server 5.0

     

    $ bin/mysqldump \  --user=root \  --password=the_mysql_root_password  \  --result-file=dump_of_all_databases_from_old_server.sql \  --all-databases

    72 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    73/202

    $ bin/mysqladmin --user root --password=the_mysql_root_password  shutdown

    mysqlshow 

    $ bin/mysqlshow --user root --password=the_mysql_root_password 

    SHOW DATABASES 

    $ bin/mysql \  --user root \  --password=the_mysql_root_password  \

      bin/mysql \

      --user=root \  --password=the_mysql_root_password  \  --database=mysql \  < scripts\mysql_fix_privilege_tables.sql

    Upgrading an Existing MySQL Server | 73

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    74/202

    $ sudo /usr/local/mysql/bin/mysql_fix_privilege_tables \  --user=root \  --password=the_mysql_root_password 

    Configuring Access to the MySQL Server

         MYSQL enable-named-pipe 

    skip-networking enable-named-pipe 

     

      bin 

    $ bin/mysql_secure_installation

    ...Change the root password? [Y/n] n

    ...Remove anonymous users? [Y/n] y...Disallow root login remotely? [Y/n] y...Remove test database and access to it? [Y/n] n...

    74 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    75/202

    Reload privilege tables now? [Y/n] y...

    ...

    What If Things Don’t Work?

    Can’t Download Files from Behind a Proxy wget yum apt-get 

    # export http_proxy=http:// proxy_username:mypass@server_name:port# export ftp_proxy=http:// proxy_username:mypass@server_name:port

    # export http_proxy=http://adam:[email protected]:8080# export ftp_proxy=http://adam:[email protected]:8080

    rpm 

    wget rpm --upgrade  dpkg --install 

    Error Message About MySQL Executable Programs Not Being Foundor Recognized mysqld_safe  mysqld-nt.exe  mysql  mysqladmin   

              

    What If Things Don’t Work? | 75

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    76/202

     

          

           

      

    find mysqld_safe 

    # find / -name mysqld_safe

    root  

    $ /usr/local/mysql/ mysqladmin status

    C:\> "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqladmin status

    bin 

    $ mysqladmin status

    command not found

    'mysqladmin' is not recognized as an internal or external command,

    operable program or batch file.

     

    $ echo $PATH

    76 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    77/202

     

     

    export PATH=$PATH:/usr/local/mysql/bin:

    bash tcsh    

    setenv PATH $PATH:/usr/local/mysql/bin

    $ source ~/.bashrc

       

    ;C:\Program Files\MySQL\MySQL Server 5.0\bin

    What If Things Don’t Work? | 77

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    78/202

    Error Message Running mysql_install_db mysql_install_db

    $ bin/mysql_install_dbInstalling all prepared tables/home/saied/mysql/libexec/mysqld: Can't read dir of '/root/tmp/' (Errcode: 13)Fill help tables/home/saied/mysql/libexec/mysqld: Can't read dir of '/root/tmp/' (Errcode: 13)...

    $ export TMPDIR=/tmp

      

    Server Doesn’t Start

    mysqld_safe  root sudo  mysqld_safe

    port 

    nmap 

      localhost

    $ nmap localhost

    Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2006-07-23 02:09 ESTInteresting ports on saied-ltc.cs.rmit.edu.au (127.0.0.1):Not shown: 1669 closed portsPORT STATE SERVICE22/tcp open ssh25/tcp open smtp80/tcp open http

    78 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    79/202

    143/tcp open imap631/tcp open ipp1494/tcp open citrix-ica3306/tcp open mysql6000/tcp open X118080/tcp open http-proxy32770/tcp open sometimes-rpc3

    Nmap finished: 1 IP address (1 host up) scanned in 0.472 seconds

    data          

                

                

    more 

    $ more  /var/lib/mysql/eden.err 050813 22:31:04 mysqld started050813 22:31:04 InnoDB: Operating system error number 13 in a file operation.InnoDB: The error means mysqld does not have the access rights to

    InnoDB: the directory.InnoDB: File name ./ibdata1InnoDB: File operation call: 'create'.InnoDB: Cannot continue operation.050813 22:31:04 mysqld ended

    more 

         

    Client Programs Can’t Connect to the Server

    user  password

    What If Things Don’t Work? | 79

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    80/202

    mysqladmin status 

    localhost    socket 

    localhost port 

    localhost skip-networking 

    localhost

    Server Doesn’t Stop

    $ bin/mysqladmin shutdownmysqladmin: shutdown failed; error: 'Access denied; you need the SHUTDOWN privilegefor this operation'

    root 

    adam

    $ bin/mysqladmin --user=root --password-che-root.passwordshutdownSTOPPING server from pid file /var/run/mysql.pid060706 21:04:02 mysqld ended

    80 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    81/202

    The Contents of the MySQL Directory

     

     

       

         

        mysqld_safe  mysqladmin

     

    mysql test  mysql  test 

         

    $ info mysql.info

    info 

     

    C:\Program Files\MySQL\MySQL Server 5.0> hh manual.chm

    The Contents of the MySQL Directory | 81

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    82/202

     

     

     

     

     

     

     

    man 

    $ man  mysqldump

       

    export MANPATH=$MANPATH:/usr/local/mysql/man

    $ source ~/.bashrc

     

    $ man /usr/local/mysql/man/man1/mysqldump.1

     

    82 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    83/202

     

                

     

    Configuring and Controlling the Apache Web Server

          

     

    Configuring and Controlling the Apache Web Server | 83

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    84/202

    apachectl 

    The Apache Document Root  

                

     

     

       

             

    su - 

    # ls --directory /var/www/html /var/www/htdocs /var/www /usr/local/apache/htdocs/bin/ls: /var/www/htdocs: No such file or directory/bin/ls: /usr/local/apache/htdocs: No such file or directory/var/www /var/www/html

    --directory  ls 

         htdocs

    # find / -type d -name htdocs

    84 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    85/202

    The Apache Configuration File   

                  

      

     

              

              

    The Apache Error Log

               

     

          

    Starting and Stopping Apache apachectl

    Configuring and Controlling the Apache Web Server | 85

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    86/202

    apache2ctl apachectl apache2ctl

    # apachectl start

    find   

    # find / -type f -name apachectl

    find   

    # /usr/local/apache/bin/apachectl start

      

    # apachectl stop

    # apachectl restart

    Checking Whether Your Apache Installation Supports PHP   

      

    $ ls -al  /var/www/html/phpinfo.php-rw------- 1 saied saied 20 Jul 22 11:35 /var/www/html/phpinfo.php

    saied

    $ chmod u=rw,g=r,o=r  path_to_document_root/ phpinfo.php

    86 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    87/202

    $ ls -al  path_to_document_root/ phpinfo.php-rw-r--r-- 1 saied saied 20 Jul 22 11:35 /var/www/html/phpinfo.php

     

     

      

     

    AddType application/x-httpd-php .php

    #

    LoadModule php4_module libexec/libphp4.soLoadModule php5_module libexec/libphp5.so

    php5_module  

    Configuring and Controlling the Apache Web Server | 87

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    88/202

    Setting up Perl

    Checking Your Existing Setup perl which 

    $ which perl/usr/bin/perl

     

           

    $ perl --version

    C:\> C:\Program Files\xampp\perl\bin\perl --version

    $ /Applications/xampp/xamppfiles/bin/perl --version

    88 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    89/202

      perl 

    command not found  'perl' is not recognizedas an internal or external command, operable program or batch file   

       

    $ perl -mDBI -e ''

    $ perl -mCGI -e ''

    $ perl -e "use DBI; foreach $d (DBI->available_drivers()){print $d;}"DBMExamplePFileSpongemysql

    Installing the Perl DBI and CGI Modules

    Installing Perl modules under Linux

    su -

    Setting up Perl | 89

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    90/202

    # perl -MCPAN -e 'install DBI'# perl -MCPAN -e 'install DBD::mysql;'# perl -MCPAN -e 'install CGI;'

    Are you ready for manual configuration? [yes]

          

       

    # yum update perl-DBI perl-DBD-mysql perl-CGI

    # urpmi perl-DBI perl-DBD-mysql perl-CGI

    # apt-get install libdbi-perl libdbd-mysql-perl libcgi-pm-perl

    Installing Perl modules under Windows

       

       

    C:\> ASSOC .pl=PerlScriptC:\> FTYPE PerlScript=C:\Program Files\xampp\perl\bin\perl.exe %1 %*

     

    90 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    91/202

    Installing Perl modules under Mac OS X    

         

    $ sudo /Applications/xampp/xamppfiles/mampp start

     

    $ ln -s /Applications/xampp/xamppfiles/var/mysql/mysql.sock /tmp/mysql.sock

        

    $ sudo chmod u=rwx,g=rx,o=rx /Applications/xampp/xamppfiles/lib/perl5

    $ sudo /Applications/xampp/xamppfiles/bin/perl -MCPAN -e 'install DBI;'$ sudo /Applications/xampp/xamppfiles/bin/perl -MCPAN -e 'install DBD::mysql;'$ sudo /Applications/xampp/xamppfiles/bin/perl -MCPAN -e 'install CGI;'

    Are you ready for manual configuration? [yes]

    no 

    Problems installing the Perl modules

    Error: Unable to locate installed Perl libraries or Perl source code.

    It is recommended that you install perl in a standard location before

    Setting up Perl | 91

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    92/202

    building extensions. Some precompiled versions of perl do not containthese header files, so you cannot build extensions. In such a case,please build and install your perl from a fresh perl distribution. Itusually solves this kind of problem.

    (You get this message, because MakeMaker could not find"/System/Library/Perl/5.8.1/darwin-thread-multi-2level/CORE/perl.h")# Looks like your test died before it could output anything.Running make testMake had some problems, maybe interrupted? Won't testRunning make installMake had some problems, maybe interrupted? Won't install

        

      

    Writing Makefile for DBD::mysql-- NOT OKRunning make testCan't test without successful make

    Running make installmake had returned bad status, install seems impossible

    $ ls ~/.cpan/buildDBD-mysql-3.0002 DBI-1.48

    $ cd ~/.cpan/build/ DBI-1.48

    make 

    $ make

    $ sudo make install

    92 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    93/202

    Resources

     

     

     

           

        

     

    Resources | 93

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    94/202

    Exercises

     

    94 | Chapter 2: Installing MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    95/202

    CHAPTER 3

    Using the MySQL Monitor

     

    Starting the Monitor mysql 

    root 

    $ mysql --user=root

    root 

    $ mysql --user=root --password=the_mysql_root_password 

    95

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    96/202

    mysql 

    mysql

    $ mysql \ --socket=server_socket \ --user=root \ --password=the_mysql_root_password 

    $mysql \ --host=server_host_name \ --port=server_port \ --user=root \ --password=the_mysql_root_password 

    port socket  user  password

    mysql> 

    Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 456 to server version: 5.0.22

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

    mysql>

    mysql> SELECT VERSION();+------------+| VERSION() |+------------+| 5.0.22 |+------------+

    1 row in set (0.03 sec)

    mysql> SHOW DATABASES;+----------+| Database |+----------+

    96 | Chapter 3: Using the MySQL Monitor

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    97/202

    | mysql || test |+----------+2 rows in set (0.00 sec)

    mysql  test

    Style, Case, and Semicolons

    SELECT  FROM USE 

    SELECT select Select SeLeCt 

    mysqld

    from  select

    ;

    mysql> SELECT User,Host  -> FROM user;+------+--------------------------+

    Style, Case, and Semicolons | 97

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    98/202

    | User | Host |+------+--------------------------+| | localhost || root | localhost || | saied-ltc.cs.rmit.edu.au || root | saied-ltc.cs.rmit.edu.au |+------+--------------------------+4 rows in set (0.00 sec)

    ->

     

    SELECT  SEL ECT

    USE 

    mysql> USE testDatabase changed

    mysql> USE

    ERROR:USE must be followed by a database name

    The Monitor Help HELP 

    mysql> HELPFor information about MySQL products and services, visit: http://www.mysql.com/For developer information, including the MySQL Reference Manual, visit: http://dev.mysql.com/To buy MySQL Network Support, training, or other products, visit: https://shop.mysql.com/

    List of all MySQL commands:Note that all text commands must be first on line and end with ';'? (\?) Synonym for `help'.clear (\c) Clear command.connect (\r) Reconnect to the server. Optional arguments are db and host.delimiter (\d) Set statement delimiter. NOTE: Takes the rest of the line as new

    98 | Chapter 3: Using the MySQL Monitor

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    99/202

      delimiter.edit (\e) Edit command with $EDITOR.ego (\G) Send command to mysql server, display result vertically.exit (\q) Exit mysql. Same as quit.go (\g) Send command to mysql server.help (\h) Display this help.nopager (\n) Disable pager, print to stdout.notee (\t) Don't write into outfile.pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.print (\p) Print current command.prompt (\R) Change your mysql prompt.quit (\q) Quit mysql.rehash (\#) Rebuild completion hash.source (\.) Execute an SQL script file. Takes a file name as an argument.status (\s) Get status information from the server.

    system (\!) Execute a system shell command.tee (\T) Set outfile [to_outfile]. Append everything into given outfile.use (\u) Use another database. Takes database name as argument.charset (\C) Switch to another charset. Might be needed for processing binlog with  multi-byte charsets.warnings (\W) Show warnings after every statement.nowarning (\w) Don't show warnings after every statement.

    For server side help, type 'help contents'

    USE  test  \u USE

    Tab  re \#

    mysql> HELP ContentsYou asked for help about help category: "Contents"

    For more information, type 'help ', where is one of the followingcategories: Account Management Administration Data Definition Data Manipulation Data Types Functions Functions and Modifiers for Use with GROUP BY

    The Monitor Hel p | 99

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    100/202

     Geographic Features Language Structure Storage Engines Stored Routines Table Maintenance Transactions Triggers

    mysql> HELP Data ManipulationYou asked for help about help category: "Data Manipulation"

    For more information, type 'help ', where is one of the followingtopics: CACHE INDEX ... DELETE ... EXPLAIN ... INSERT ... SELECT ... SHOW ... SHOW CREATE DATABASE ... SHOW CREATE TABLE ... SHOW DATABASES ... SHOW GRANTS ... SHOW STATUS ... SHOW TABLES ... UPDATE

    SHOW DATABASES 

    mysql> HELP SHOW DATABASESName: 'SHOW DATABASES'Description:Syntax:SHOW {DATABASES | SCHEMAS} [LIKE 'pattern']

    100 | Chapter 3: Using the MySQL Monitor

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    101/202

    SHOW DATABASES lists the databases on the MySQL server host. You seeonly those databases for which you have some kind of privilege, unlessyou have the global SHOW DATABASES privilege. You can also get thislist using the mysqlshow command.

    If the server was started with the --skip-show-database option, youcannot use this statement at all unless you have the SHOW DATABASESprivilege.

    SHOW SCHEMAS can be used as of MySQL 5.0.2

    Running the Monitor in Batch Mode  

    SHOW DATABASES 

     

    use mysql;SELECT COUNT(*) FROM user;

    mysql  SELECT 

    SOURCE 

    mysql> SOURCE count_users.sqlDatabase changed+----------+| count(*) |+----------+| 4 |

    +----------+1 row in set (0.00 sec)

        

    Running the Monitor in Batch Mode | 101

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    102/202

    $ mysql --user=root --password=the_mysql_root_password  < count_users.sqlcount(*)4

    Loading the Sample Databases  

    SOURCE  music.sql     

      

    SOURCE 

    mysql> SOURCE  path_to_music.sql_file;Query OK, 1 row affected (0.00 sec)

    Query OK, 1 row affected (0.01 sec)

    Query OK, 1 row affected (0.00 sec)...

    SHOW DATABASES 

    mysql> SHOW DATABASES;+----------+

    | Database |+----------+| music || mysql || test |+----------+3 rows in set (0.00 sec)

    mysql>

       quit

    mysql> quit

    MySQL Monitor Program Options

    102 | Chapter 3: Using the MySQL Monitor

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    103/202

    host localhost

    user

      ODBC 

    password

    password 

    $ mysql --user=the_usernameERROR 1045 (28000): Access denied for user 'the_username'@'localhost'  (using password: NO)

    password 

    $ mysql --user=the_username --passwordEnter password:ERROR 1045 (28000): Access denied for user 'the_username'@'localhost'  (using password: NO)

    $ mysql --user=the_username --password=wrong_password Enter password:ERROR 1045 (28000): Access denied for user 'the_username'@'localhost'  (using password: YES)

    Enter password: 

    $ mysql --user=the_username --password=the_password Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 169 to server version: 5.0.22

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

    mysql>

    MySQL Monitor Program Options | 103

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    104/202

    database

    the_database_name database 

      mysql 

    safe-updates

    DELETE FROM table_name 

    safe-updates 

    DELETE  UPDATE LIMIT  mysql> DELETE FROM user;ERROR 1175 (HY000): You are using safe update mode and you tried to update  a table without a WHERE that uses a KEY column

    localhost root the_mysql_root_password  music

    $ mysql --user=root --password=the_mysql_root_password  --database=music

    Moodle  moodleuser  moodlepass

    $ mysql \  --host=zahra.learningmysql.com \  --port=57777 \  --user=moodleuser \  --password=moodlepass \  --database=Moodle

    mysql

    Graphical Clients

    104 | Chapter 3: Using the MySQL Monitor

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    105/202

    mysqlcc

    Exercises

    SELECT 

    SELECT 

    user password database 

    Exercises | 105

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    106/202

    106 | Chapter 3: Using the MySQL Monitor

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    107/202

    PART II

    Using MySQL

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    108/202

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    109/202

    CHAPTER 4

    Modeling and Designing Databases

    How Not to Develop a Database

    Student_Grades  Pctg

    +------------+---------+---------------------------+------+| GivenNames | Surname | CourseName | Pctg |+------------+---------+---------------------------+------+

    | John Paul | Bloggs | Web Database Applications | 72 || Sarah | Doe | Programming 1 | 87 || John Paul | Bloggs | Computing Mathematics | 43 || John Paul | Bloggs | Computing Mathematics | 65 || Sarah | Doe | Web Database Applications | 65 || Susan | Smith | Computing Mathematics | 75 || Susan | Smith | Programming 1 | 55 || Susan | Smith | Computing Mathematics | 80 |+------------+---------+---------------------------+------+

    109

  • 8/19/2019 Aprenda Mysql by Oreilly Introd

    110/202

    +------------+------------+---------+---------------------------+------+| StudentID | GivenNames | Surname | CourseName | Pctg |+------------+------------+---------+---------------------------+------+| 12345678 | John Paul | Bloggs | Web Database Applications | 72 || 12345121 | Sarah | Doe | Programming 1 | 87 || 12345678 | John Paul | Bloggs | Computing Mathematics | 43 || 12345678 | John Paul | Bloggs | Computing Mathematics | 65 |

    | 12345121 | Sarah | Doe | Web Database Applications | 65 || 12345876 | Susan | Smith | Computing Mathematics | 75 || 12345876 | Susan | Smith | Programming 1 | 55 || 12345303 | Susan | Smith | Computing Mathematics | 80 |+------------+------------+---------+---------------------------+------+

     

    Sem+------------+------------+---------+---------------------------+------+-----+------+| StudentID | GivenNames | Surname | CourseName | Year | Sem | Pctg |+------------+------------+---------+---------------------------+------+-----+-----