Setting Up MySQL


MySQL is a free download that is available from http://dev.mysql.com for every major computing platform. You'll want to download and install the most current MySQL distribution available for your platform. We'll be working from the MySQL Standard 4.1.8 GA version.

We'll assume you can follow the instructions for installing MySQL on your platform. Once you have MySQL running, you'll need to create a database to be used by JBoss. You'll also need to create a database user that has access to the JBoss database for JBoss to use.

How do I do that?

MySQL is administered using the mysql command found in your MySQL installation. On our machine it is found in /usr/local/mysql/bin/mysql. You'll want to run with the mysql client as the root user, using the -u option:

     $ /usr/local/mysql/bin/mysql -u root     Welcome to the MySQL monitor.  Commands end with ; or \g.     Your MySQL connection id is 4 to server version: 4.1.8-standard     Type 'help;' or '\h' for help. Type '\c' to clear the buffer.     mysql> 

After connecting to the database, we'll create a database named jbossdb, using the create database command:


Note: If you want to run MySQL on a different host, you need to give the database user access from the host JBoss is running on.
     mysql> create database jbossdb;     Query OK, 1 row affected (0.01 sec) 

Now we need to create a user account to be used when accessing the jbossdb database. The grant command accomplishes this:

     mysql> grant all privileges on jbossdb.* to todoapp@localhost identified     by 'secretpassword';     Query OK, 0 rows affected (0.38 sec) 

This creates a user called todoapp whose password is secretpassword. This user is granted full rights to everything in the jbossdb database when connecting from the same host. You can examine the mysql.user table to verify that the user was created correctly:

     mysql> select user,host,password from mysql.user;     +-----------+------------+-------------------------------------------+     | user      | host       | password                                  |     +-----------+------------+-------------------------------------------+     | root      | localhost  |                                           |     | root      | toki.local |                                           |     |           | toki.local |                                           |     |           | localhost  |                                           |     | todoapp   | localhost  | *F89FFE84BFC48A876BC682C4C23ABA4BF64711A4 |     +-----------+------------+-------------------------------------------+     6 rows in set (0.00 sec) 

Note that todoapp only has permission to access the database locally, and has no remote access. You can test the username and password using the -u and -password options:

     $ /usr/local/mysql/bin/mysql -u todoapp --password=secretpassword 

You can also test remote access to the database by running the mysql command from a remote machine, using the -h option to specify the machine that is running MySQL. Since we've only granted access from localhost, the access attempts should fail.

What just happened?

You've created a database to be used by JBoss, and you've created a user who has permission to access the database. You don't need to worry about creating special tables or loading any data. JBoss will take care of creating the database tables needed.



JBoss. A Developer's Notebook
JBoss: A Developers Notebook
ISBN: 0596100078
EAN: 2147483647
Year: 2003
Pages: 106

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