8.2. MySQL as the Default Datasource
The MySQL® database has become the most popular open source database. We will configure a datasource to this database for demonstration purposes.
In this example we are using MySQL 5.1.31 and
Connector/J
5.1.8, the official JDBC driver. Both are available at www.mysql.com.
8.2.1. Creating a Database and User
We’ll assume that you have already installed MySQL, have it running, and are familiar with the basics. Run the MySQL client program from the command line so we can execute some administration commands. You should make sure that you are connected as a user with sufficient privileges (for example, by specifying the
-u
root option to run as the MySQL root user).
First create a database called
jboss
within MySQL for use by JBoss:
mysql> CREATE DATABASE jboss; Query OK, 1 row affected (0.05 sec)
Then check that it has been created:
mysql> SHOW DATABASES; +----------+ | Database | +----------+ | jboss | +----------+ 1 rows in set (0.00 sec)
Next, create a user called
jboss
with 'password' as the password to access the database:
mysql> GRANT ALL PRIVILEGES ON jboss.* TO jboss@localhost IDENTIFIED BY 'password'; Query OK, 0 rows affected (0.06 sec)
Again, you can check that everything has gone smoothly:
mysql> select User,Host,Password from mysql.user; +-------+-----------+------------------+ | User | Host | Password | +-------+-----------+------------------+ | root | localhost | | | root | % | | | | localhost | | | | % | | | jboss | localhost | 5d2e19393cc5ef67 | +-------+-----------+------------------+ 5 rows in set (0.02 sec)