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)
Copy to Clipboard Toggle word wrap
Then check that it has been created:
mysql> SHOW DATABASES;
+----------+
| Database |
+----------+
| jboss    |
+----------+
1 rows in set (0.00 sec)
Copy to Clipboard Toggle word wrap
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)
Copy to Clipboard Toggle word wrap
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)
Copy to Clipboard Toggle word wrap
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat