Page 390 - Beginning PHP 5.3
P. 390

Part III: Using PHP in Practice
                      5.       Add passwords for the  root  users  —  Type the following lines, replacing  mypass  with the pass-
                       word you want to use and   mattscomputer  with the host name of your computer (shown in the
                         Host  column in the table), and pressing Enter after each line:

                    SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘mypass’);
                    SET PASSWORD FOR ‘root’@’mattscomputer’ = PASSWORD(‘mypass’);
                    SET PASSWORD FOR ‘root’@’127.0.0.1’ = PASSWORD(‘mypass’);

                      You only need to enter the lines that correspond to the  root  entries shown in the table. For example,
                    if your table doesn ’ t include the line with the   127.0.0.1  host, you can omit the third  SET PASSWORD  line.
                      Make sure you choose a secure password. At a minimum, this should be at least 7 characters long, and
                    contain a mixture of letters and numbers.
                      6.       Check that the passwords have been set  —  Retype the  SELECT  line from Step 4 and press Enter.
                       You should see that the three   root  users now have their  Password  columns set:

                    +---------------+------+-------------------------------------------+
                    | Host          | User | Password                                  |
                    +---------------+------+-------------------------------------------+
                    | localhost     | root | *D8DECEC305209EEFEC43008E1D420E1AA06B19E0 |
                    | mattscomputer | root | *D8DECEC305209EEFEC43008E1D420E1AA06B19E0 |
                    | 127.0.0.1     | root | *D8DECEC305209EEFEC43008E1D420E1AA06B19E0 |
                    | localhost     |      |                                           |
                    | mattscomputer |      |                                           |


                    +---------------+------+-------------------------------------------+
                      7.       Exit the MySQL command - line tool  —  Type  exit  and then press Enter to return to the shell
                       prompt.
                  Now that you ’ ve added a password for the   root  account, your MySQL server is relatively secure. To test
                the new password, run the   mysql  command again, but this time, add a   -   (hyphen followed by   “   ” )
                                                                          p
                                                                                              p
                 to the end of the command line, as follows:
                    mysql -u root -p    # Ubuntu, Windows
                    ./mysql -u root -p  # Mac OS X

                   MySQL will prompt you for the  root  password that you entered previously. Type it now, then press
                Enter. If all goes well you should be back at the   mysql >   prompt. Again, type  exit  and press Enter to exit
                 the program.

                      If you get an  “ Access denied ”  error, try again. If you still can ’ t get access, you may need to reinstall
                    your MySQL server. Alternatively you may be able to reset the root password. See the section titled
                      “ How to Reset the Root Password ”  in the MySQL reference manual at   http://dev.mysql.com/
                    doc/refman/5.1/en/resetting-permissions.html  .

                   You can now use this   root  user to create and work with databases in your MySQL system. The PHP
                scripts you create later will also use the   root  user to connect to your MySQL database. Though this is
                 fine for development and testing purposes, you should not use the   root  user in your PHP scripts on a
                 live server. Instead, create a new MySQL user that has only the privileges that your script needs. (If
                 you ’ re running your site on a shared server, your hosting company will probably give you a username
                 and password to use.)

              352





                                                                                                      9/21/09   9:11:11 AM
          c12.indd   352
          c12.indd   352                                                                              9/21/09   9:11:11 AM
   385   386   387   388   389   390   391   392   393   394   395