PHP

Configuring MySQL

The following steps create a user for the MySQL installation that is used in PHP scripts to access the DBMS. The user can carry out all actions required in Chapter 4 to Chapter 13 on the winestore database but has no access to other databases and can't change database access privileges. In addition, the new user can't access the DBMS from a remote server, under the assumption that the MySQL DBMS and Apache are installed on the same machine through following the instructions in this appendix.

The steps are as follows:

  1. Check that MySQL is running using the password defined in Step 19 of the MySQL installation instructions:

    % /usr/local/mysql/bin/mysqladmin -psecret version
    

    If it isn't, then log in as the root user and start the MySQL DBMS using:

    % /usr/local/mysql/bin/safe_mysqld --user=mysql &
    
  2. Start the MySQL command line interpreter using the same password as in the last step:

    % /usr/local/mysql/bin/mysql -psecret
    
  3. Add a new user to the user table in the mysql database. Choose a username to replace username and a password to replace secret in the following command:

    GRANT ALL PRIVILEGES ON winestore.* TO username@localhost
    IDENTIFIED BY 'secret';
    

    MySQL responds with:

    Query OK, 0 rows affected (0.00 sec)
    

    Record the username and password for use in the examples in Chapter 3 to Chapter 13.

  4. Quit the MySQL command interpreter with the command:

    quit
    

    MySQL responds with:

    Bye
    
  5. Test the user created in Step 3 by running the MySQL command interpreter using the username and password:

    % /usr/local/mysql/bin/mysql -uusername -psecret
    

    MySQL responds with a message beginning:

    Welcome to the MySQL monitor.
    
  6. Quit the MySQL interpreter again with:

    quit
    

The MySQL DBMS is now configured with a user who can access the winestore database from the database server machine localhost. The winestore database can't be tested yet; the winestore database is loaded and tested in Section 3.2 in Chapter 3.

by BrainBellupdated
Advertisement: