Setting up MySQL

This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Setting up MySQL

The following sections describe how to set up a MySQL database to replace the default H2 database in your WSO2 product:

Setting up the database and users

Follow the steps below to set up a MySQL database:

  1. Download and install MySQL on your computer using the following command:



    sudo apt-get install mysql-server mysql-client
  2. Start the MySQL service using the following command:

    sudo /etc/init.d/mysql start
  3. Log in to the MySQL client as the root user (or any other user with database creation privileges).

    mysql -u root -p
  4. Enter the password when prompted.

  5. In the MySQL command prompt, create the database using the following command:

    create database regdb;



  6. Give authorization to the regadmin user as follows:

    GRANT ALL ON regdb.* TO regadmin@localhost IDENTIFIED BY "regadmin";
  7. Once you have finalized the permissions, reload all the privileges by executing the following command: 

    FLUSH PRIVILEGES;
  8. Log out from the MySQL prompt by executing the following command:

    quit;

Setting up the drivers

Download the MySQL Java connector JAR file, and copy it to the <PRODUCT_HOME>/repository/components/lib/ directory.

Be sure to use the connector version that is supported by the MySQL version you use. If you come across any issues due to version incompatibility, follow the steps below:

  1. Shut down the server and remove all existing connectors from <PRODUCT_HOME>/repository/components/lib and <PRODUCT_HOME>/repository/components/dropins.

  2. Download the connector JAR that is compatible with your current MySQL version.

  3. Copy the JAR file only to <PRODUCT_HOME>/repository/components/lib. Files will be copied automatically to the dropins folder during server startup.

  4. Start the server with the -Dsetup parameter as sh wso2server.sh -Dsetup.

Executing db scripts on MySQL database

To run the database script against the database you created, login to the MySQL client and point to the corresponsing database.

use regdb;

Execute the mysql.sql database script against the pointed database using following command.

mysql> source <path to the script>\mysql.sql;

 If you are using MySQL 5.7 or later version, use mysql5.7.sql script and execute the above command modified as following.

mysql> source <path to the script>\mysql5.7.sql;


What's next

By default, all WSO2 products are configured to use the embedded H2 database. To configure your product with MySQL, see Changing to MySQL.