Developers: Learn a New Programming Language or App Development with Deitel LiveLessons Videos!
s
menu
menu
Login  |  Register  |  Media Kit  |  Press  |  Contact Us  |   Twitter Become a Deitel Fan on Facebook  
Custom Search

Updated MySQL Setup Instructions for Java How to Program, 8/eMinimize

For those of you who might be using Java How to Program, 8/e, with newer versions of MySQL than we used in that edition, here are some updated instructions:

 

Instructions for Installing MySQL and MySQL Connector/J

MySQL Community Edition is an open-source database management system that executes on many platforms, including Windows, Linux, and Mac OS X. Complete information about MySQL is available from www.mysql.com. The examples in Sections 28.8–28.9 manipulate MySQL databases using MySQL 5.5.8—the latest release at the time of this writing. 

 

Installing MySQL

To install MySQL Community Edition on Windows, Linux or Mac OS X, see the installation overview for your platform at: 

  • Windows: http://dev.mysql.com/doc/refman/5.5/en/windows-installation.html
  • Linux: http://dev.mysql.com/doc/refman/5.5/en/linux-installation-rpm.html
  • Mac OS X: http://dev.mysql.com/doc/refman/5.5/en/macosx-installation.html

Carefully follow the instructions for downloading and installing the software on your platform. The downloads are available from:

  • http://dev.mysql.com/downloads/mysql/

For the following steps, we assume that you’re installing MySQL on Windows. When you execute the installer, the MySQL Server 5.5 Setup Wizard window will appear. Perform the following steps:

  • Click the Next button.
  • Read the license agreement, then check the I accept the terms in the License Agreement checkbox and click the Next button. [Note: If you do not accept the license terms, you will not be able to install MySQL.] 
  • Click the Typical button in the Choose Setup Type screen then click Install.
  • When the installation completes, click Next > twice.  
  • In the Completed the MySQL Server 5.5 Setup Wizard screen, ensure that the Launch the MySQL Instance Configuration Wizard checkbox is checked, then click Finish to begin configuring the server. 

The MySQL Instance Configuration Wizard window appears. To configure the server:

Click Next >, then select Standard Configuration and click Next > again.

  • You have the option of installing MySQL as a Windows service, which enables the MySQL server to begin executing automatically each time your system starts. For our examples, this is unnecessary, so you can uncheck Install as a Windows Service if you wish. Check Include Bin Directory in Windows PATH. This will enable you to use the MySQL commands in the Windows Command Prompt. Click Next >, then click Execute to perform the server configuration. 
  • Click Finish to close the wizard.

You’ve now completed the MySQL installation.

 

Installing MySQL Connector/J

To use MySQL with JDBC, you also need to install MySQL Connector/J (the J stands for Java)—a JDBC driver that allows programs to use JDBC to interact with MySQL. MySQL Connector/J can be downloaded from

  • http://dev.mysql.com/downloads/connector/j/

The documentation for Connector/J is located at 

  • http://dev.mysql.com/doc/refman/5.5/en/connector-j.html

At the time of this writing, the current generally available release of MySQL Connector/J is 5.1.14. To install MySQL Connector/J, carefully follow the installation instructions at:

  • http://dev.mysql.com/doc/refman/5.5/en/connector-j-installing.html

We do not recommend modifying your system’s CLASSPATH environment variable, which is discussed in the installation instructions. Instead, we’ll show you how use MySQL Connector/J by specifying it as a command-line option when you execute your applications.

 

Instructions for Setting Up a MySQL User Account

For the MySQL examples to execute correctly, you need to set up a user account that allows users to create, delete and modify a database. After MySQL is installed, follow the steps below to set up a user account (these steps assume MySQL is installed in its default installation directory):

  • Open a Command Prompt and start the database server by executing the command mysqld.exe. This command has no output—it simply starts the MySQL server. Do not close this window—doing so terminates the server.
  • Next, you’ll start the MySQL monitor so you can set up a user account, open another Command Prompt and execute the command 

           mysql -h localhost -u root

  • The -h option indicates the host (i.e., computer) on which the MySQL server is running—in this case your local computer (localhost). The -u option indicates the user account that will be used to log in to the server—root is the default user account that is created during installation to allow you to configure the server. Once you’ve logged in, you’ll see a mysql> prompt at which you can type commands to interact with the MySQL server.
  • At the mysql> prompt, type 

          USE mysql;

  • and press Enter to select the built-in database named mysql, which stores server information, such as user accounts and their privileges for interacting with the server. Each command must end with a semicolon. To confirm the command, MySQL issues the message “Database changed.”
  • Next, you’ll add the deitel user account to the mysql built-in database. The mysql database contains a table called user with columns that represent the user’s name, password and various privileges. To create the deitel user account with the password deitel, execute the following commands from the mysql> prompt:

          create user 'deitel'@'localhost' identified by 'deitel';

          grant select, insert, update, delete, create, drop, references, execute on *.* to 'deitel'@'localhost';

  • This creates the deitel user with the privileges needed to create the databases used in this chapter and manipulate them. Type the command 

          exit;

  • to terminate the MySQL monitor. 

Creating Database books in MySQL

For each MySQL database we discuss, we provide a SQL script in a .sql file that sets up the database and its tables. You can execute these scripts in the MySQL monitor. In this chapter’s examples directory, you’ll find the script books.sql to create the books database. For the following steps, we assume that the MySQL server (mysqld.exe) is still running. To execute the books.sql script:

  • Open a Command Prompt and use the cd command to change directories to the location that contains the books.sql script. 
  • Start the MySQL monitor by typing 

          mysql -h localhost -u deitel -p

  • The -p option prompts you for the password for the deitel user account. When prompted, enter the password deitel. Execute the script by typing 

         source books.sql;

  • This creates a new directory named books in the server’s data directory—located  by default on Windows at C:\ProgramData\MySQL\MySQL Server 5.5\data. This new directory contains the books database. 
  • Type the command 

         exit;

  • to terminate the MySQL monitor. You’re now ready to proceed to the first JDBC example. 

 

Print  

Discounts on SafariBooksOnline.com subscriptions

foot
Update :: December 17, 2017