Connecting JIRA applications to MySQL
1. Create and configure the MySQL database
- Create a database user which JIRA will connect as (e.g.
jiradbuser
).
Remember this database user name, as it will be used to configure JIRA's connection to this database in subsequent steps. Create a database for JIRA to store issues in (e.g.
jiradb
). The database must have a character set of UTF8. Enter the following command from within the MySQL command client.
Remember this database name, as it will be used to configure JIRA's connection to this database in subsequent steps.CREATE DATABASE jiradb CHARACTER SET utf8 COLLATE utf8_bin;
(if you want your database to be named
jiradb
).Ensure that the user has permission to connect to the database, and permission to create and populate tables. These can be provided with the following:
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER,INDEX on <JIRADB>.* TO '<USERNAME>'@'<JIRA_SERVER_HOSTNAME>' IDENTIFIED BY '<PASSWORD>'; flush privileges;
Tip:
To confirm if the permissions were granted successfully, log into the DB server with the JIRA DB user and run the command below:
SHOW GRANTS FOR <USERNAME>@<JIRA_SERVER_HOSTNAME>;
Edit the
my.cnf
file (my.ini
on Windows operating systems) in your MySQL server. (Refer to MySQL Option Files for detailed instructions on editingmy.cnf
andmy.ini
.)
Locate the[mysqld]
section in the file, and add or modify the following parameters:Set the default storage engine to InnoDB:
[mysqld] ... default-storage-engine=INNODB ...
Specify the value of
max_allowed_packet
to be at least 256M:[mysqld] ... max_allowed_packet=256M ...
Specify the value of
innodb_log_file_size
to be at least 256M for MySQL 5.5 and below:[mysqld] ... innodb_log_file_size=256M ...
NB: This should be set to at least 2G for MySQL 5.6 and above.
Ensure the sql_mode parameter does not specify NO_AUTO_VALUE_ON_ZERO
// remove this if it exists sql_mode = NO_AUTO_VALUE_ON_ZERO
Restart your MySQL server for the changes to take effect:
- On Windows, use the Windows Services manager to restart the service.
- On Linux:
- Run one of the following commands, depending on your setup: '
/etc/init.d/mysqld stop
' or '/etc/init.d/mysql stop
' or 'service mysqld stop
'. - Then run the same command again, replacing '
stop
' with 'start
'.
- Run one of the following commands, depending on your setup: '
2. Copy the MySQL JDBC driver to your application server
If you are upgrading JIRA and you are using the recommended MySQL driver (Connector/J JDBC driver v5.1), you can skip the instructions in this section. The JIRA upgrade task will automatically copy over your existing driver to the upgraded installation.
To copy the MySQL JDBC driver to your application server:
- Get the MySQL driver:
- If you are installing JIRA, download the recommended MySQL driver JDBC Connector/J 5.1.
You can download either the.tar.gz
or the.zip
file by selecting the 'Platform Independent' option. Extract the jar for the driver (e.g.mysql-connector-java-5.x.x-bin.jar
) from the archive. - If you are upgrading JIRA and you are not using the recommended MySQL driver (JDBC Connector/J 5.1), back up the driver from your JIRA installation before you upgrade.
The driver will be in the <JIRA installation directory>
/lib/
directory.
- If you are installing JIRA, download the recommended MySQL driver JDBC Connector/J 5.1.
- Copy the MySQL JDBC driver jar to the <
JIRA installation directory>
/lib/
directory for your new/upgraded installation. If you are installing JIRA using the Windows installer, you will need to do this step after running the Windows installer, but before running the setup wizard. - Restart JIRA / JIRA service.
- If you are installing JIRA, skip the rest of the instructions on this page and access JIRA in your browser to run the setup wizard instead.
Please note:
- We recommend the Connector/J driver from MySQL (linked above). A user has reported experiencing problems with the Resin JDBC driver for MySQL.
3. Configure your JIRA server to connect to your MySQL database
There are two ways to configure your JIRA server to connect to your MySQL database:
- Using the JIRA setup wizard — Use this method if you have just installed JIRA, and are setting it up for the first time. Your settings will be saved to the
dbconfig.xml
file in your JIRA home directory. - Using the JIRA configuration tool — Use this method, if you have an existing JIRA instance. Your settings will be saved to the
dbconfig.xml
file in your JIRA home directory.
Instructions for each configuration method
JIRA setup wizard
The JIRA setup wizard will display when you access JIRA for the first time in your browser.
- In the first screen, 'Configure Language and Database', set Database Connection to My own database.
- Set Database Type to MySQL.
- Fill out the fields, as described in the Database connection fields section below.
- Test your connection and save.
JIRA configuration tool
- Run the JIRA configuration tool as follows:
- Windows: Open a command prompt and run
config.bat
in thebin
sub-directory of the JIRA installation directory. - Linux/Unix: Open a console and execute
config.sh
in thebin
sub-directory of the JIRA installation directory.
This may fail with the error as described in our Unable to Start JIRA applications Config Tool due to No X11 DISPLAY variable was set error KB article. Please refer to it for the workaround.
- Windows: Open a command prompt and run
- Navigate to the Database tab and set Database type to MySQL.
- Fill out the fields, as described in the Database connection fields section below.
- Test your connection and save.
- Restart JIRA.
Database connection fields
Setup wizard / Configuration tool | dbconfig.xml | Description |
---|---|---|
Hostname | Located in the | The name or IP address of the machine that the MySQL server is installed on. |
Port | Located in the | The TCP/IP port that the MySQL server is listening on. You can leave this blank to use the default port. |
Database | Located in the | The name of your MySQL database (into which JIRA will save its data). You should have created this in Step 1 above. |
Username | Located in the | The user that JIRA uses to connect to the MySQL server. You should have created this in Step 1 above. |
Password | Located in the <password> tag (see bold text in example below):<password> jiradbuser</password> | The user's password — used to authenticate with the MySQL server. |
Sample dbconfig.xml file
- For more information about the child elements of
<jdbc-datasource/>
beginning withpool
in thedbconfig.xml
file above, see Tuning database connections. - Both the JIRA setup wizard and database configuration tool also add the element
<validation-query>select 1</validation-query>
to this file, which is usually required when running JIRA with default MySQL installations. See Surviving connection closures for more information. - The database URL in the example below assumes a UTF-8 database — i.e. that your database was created using a command similar to
create database jiradb character set utf8;
If you do not specifycharacter set utf8
when creating this database, you risk getting 'Data truncation: Data too long for column
' errors when importing data or corruption of non-supported characters. - The database URL in the example below contains the
sessionVariables=storage_engine=InnoDB
parameter. We strongly recommend adding this parameter to avoid data corruption.
<?xml version="1.0" encoding="UTF-8"?>
<jira-database-config>
<name>defaultDS</name>
<delegator-name>default</delegator-name>
<database-type>mysql</database-type>
<jdbc-datasource>
<url>jdbc:mysql://dbserver:3306/jiradb?useUnicode=true&characterEncoding=UTF8&sessionVariables=storage_engine=InnoDB</url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<username>jiradbuser</username>
<password>password</password>
<pool-min-size>20</pool-min-size>
<pool-max-size>20</pool-max-size>
<pool-max-wait>30000</pool-max-wait>
<pool-max-idle>20</pool-max-idle>
<pool-remove-abandoned>true</pool-remove-abandoned>
<pool-remove-abandoned-timeout>300</pool-remove-abandoned-timeout>
<validation-query>select 1</validation-query>
<min-evictable-idle-time-millis>60000</min-evictable-idle-time-millis>
<time-between-eviction-runs-millis>300000</time-between-eviction-runs-millis>
<pool-test-while-idle>true</pool-test-while-idle>
<pool-test-on-borrow>false</pool-test-on-borrow>
<validation-query-timeout>3</validation-query-timeout>
</jdbc-datasource>
</jira-database-config>
4. Start JIRA
You should now have JIRA configured to connect to your MySQL database. The next step is to start it up!
Congratulations, you now have JIRA connected to your MySQL database.
Known issues
Here's a list of known issues for this database. Expand each of them for more details.