Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 25. Accessing Databases with JDB... > Instructions for Setting Up a MySQL ...

25.6. 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):

1.
Open a Command Prompt and start the database server by executing the command mysqld-nt.exe. Note that this command has no output—it simply starts the MySQL server. Do not close this window—doing so terminates the server.

2.
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.

3.
At the mysql> prompt, type

USE mysql;

to select the built-in database named mysql, which stores server information, such as user accounts and their privileges for interacting with the server. Note that each command must end with a semicolon. To confirm the command, MySQL issues the message “Database changed.”

4.
Next, you’ll add the jhtp7 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 jhtp7 user account with the password jhtp7, execute the following commands from the mysql> prompt:

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

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

This creates the jhtp7 user with the privileges needed to create the databases used in this chapter and manipulate those databases. Next, type

5.
Type the command

exit;

to terminate the MySQL monitor.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint