Setting Up MySQL

printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    

JSTL: JSP Standard Tag Library Kick Start
By Jeff Heaton

Table of Contents
Appendix C.  Installing MySQL


Now that you've installed your MySQL database system, you must be able to launch your server. If you're using Windows XP, Windows 2000 Pro, or Windows NT, we suggest that you configure MySQL to run as a service. If you're using an older version of Windows, refer to the MySQL documentation.

If you're using Unix, you do not need to worry about services. MySQL for Unix installs to be ran as a daemon process. For more information about using Unix, refer to Appendix D, "Unix Installation Notes."

By configuring MySQL to work as a service, you are guaranteed that the MySQL database system will always be running. Services run even when no user is currently logged into the system. To set MySQL to run as a service, you have to start a command prompt window. From this window, change the current directory to the BIN directory of MySQL.

Earlier, we set up the path so that you can execute the MySQL commands from anywhere. When you're installing the service, it is important that you do not install these commands from anywhere. To install MySQL to run as a service, you must change to the c:\mysql\bin directory. To do this, issue the following command in the command prompt window:

cd \mysql\bin 

Now that you are in the BIN directory, you have to instruct MySQL to install itself as a service:

mysql-max-nt  install 

At this point, MySQL is set up to run as a service. The next time that you restart your computer, MySQL will run in the background and you can easily access it. To start the service without having to restart your computer, use this command:

net start mysql 

Now that the service is running, you can connect to your MySQL database for the first time. The following mysql command connects you to the MySQL instance you just installed (as the root user):

mysql  u root 

Notice that you are allowed to access the system with no password. This is necessary for the first-time install of MySQL. We suggest that you now change your password for security reasons. For example, this command sets the root user's password to joshua:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('joshua'); 

If you followed each of these steps correctly, your screen should look like the one in Figure C.3. You can now exit MySQL with the following command:

exit 
Figure C.3. Setting the MySQL service.

graphics/cfig03.jpg

Now you must enter MySQL with the root user and specify a password. Use the following command:

mysql  u root  p 

You are not allowed to specify your password as part of the command line because of security reasons. Other users can easily view a list of running processes for your account. This list shows all command-line parameters that you used, so if you specify your password on the command line, other users could see it. Instead, specifying the p parameter tells MySQL that you are going to log in using a password.

MySQL will now prompt you for a password. Enter joshua (or whatever you choose as your password).

Now that the root user has been properly set up, let's create the forum database that we use for the examples in this book. First, issue this command:

create database forum; 

Once you execute this command, you'll have a new database named forum. Now you have to create a user to access the forum database. We suggest you always create users specific to your Web applications. This is more secure than using the root user to access each of these databases. To create a user, you must grant the user rights.

Granting a user rights for the first time also creates that user:

grant all privileges on forum.* to forumuser@localhost 

You now have a user named forumuser that can access your forum database. If you've followed each step correctly, your screen should now look like the one in Figure C.4.

Figure C.4. Logging in using a password.

graphics/cfig04.jpg

One very important thing to note about this command is that it ties the server name to the user. If you'd like to access your database from another computer, it is necessary to also create a user account for that machine. For example, if you want to access the forum database from a computer with the IP address of 192.168.1.100, issue the following command:

grant all privileges on forum.* to forumuser@192.168.1.100 

You have now successfully installed MySQL and created a database to hold the forum application. In the next section, you'll learn how to create tables inside the forum database.


    printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    
    Top

    [0672324504/app03lev1sec2]

     
     


    JSTL. JSP Standard Tag Library Kick Start
    JSTL: JSP Standard Tag Library Kick Start
    ISBN: 0672324504
    EAN: 2147483647
    Year: 2001
    Pages: 93
    Authors: Jeff Heaton

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net