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/.
Changing to MySQL
By default, WSO2 products use the embedded H2 database as the database for storing user management and registry data. Given below are the steps you need to follow in order to use a MySQL database for this purpose.
Before you begin
You need to set up MySQL before following the steps to configure your product with MySQL. For more information, see Setting up MySQL.
Creating the datasource connection to MySQL
A datasource is used to establish the connection to a database. By default, WSO2_CARBON_DB datasource is configured in the master-datasources.xml file for the purpose of connecting to the default H2 database, which stores registry and user management data.
After setting up the MySQL database to replace the default H2 database, either change the default configurations of the WSO2_CARBON_DB datasource, or configure a new datasource to point it to the new database as explained below.
Follow the steps below to change the type of the default WSO2_CARBON_DB datasource.
Open the <
PRODUCT_HOME>/repository/conf/datasources/master-datasources.xmlfile and locate the<datasource>configuration element.You simply have to update the URL pointing to your MySQL database, the username, and password required to access the database and the MySQL driver details as shown below.
<datasource> <name>WSO2_CARBON_DB</name> <description>The datasource used for registry and user manager</description> <jndiConfig> <name>jdbc/WSO2CarbonDB</name> </jndiConfig> <definition type="RDBMS"> <configuration> <url>jdbc:mysql://localhost:3306/regdb</url> <username>regadmin</username> <password>regadmin</password> <driverClassName>com.mysql.jdbc.Driver</driverClassName> <maxActive>80</maxActive> <maxWait>60000</maxWait> <minIdle>5</minIdle> <testOnBorrow>true</testOnBorrow> <validationQuery>SELECT 1</validationQuery> <validationInterval>30000</validationInterval> <defaultAutoCommit>false</defaultAutoCommit> </configuration> </definition> </datasource>You can update the configuration elements given below for your database connection.
Updating other configuration files
The
registry.xmlfile (stored in the<PRODUCT_HOME>/repository/confdirectory) specifies the datasource information corresponding to the database that stores registry information. Therefore, if you have changed the datasource name, you need to update the following accordingly:<dbConfig name="wso2registry"> <dataSource>jdbc/MY_DATASOURCE_NAME</dataSource> </dbConfig>The
user-mgt.xmlfile (stored in the<PRODUCT_HOME>/repository/confdirectory) specifies the datasource information corresponding to the database that stores user management information. Therefore, if you have changed the datasource name, you need to update the following accordingly:<Configuration> <Property name="dataSource">jdbc/MY_DATASOURCE_NAME</Property> </Configuration>
Creating database tables
To create the database tables, connect to the database that you created earlier and run the relevant scripts.
Alternatively, you can create database tables automatically when starting the product for the first time by using the -Dsetup parameter as follows:
For Windows:
<PRODUCT_HOME>/bin/wso2server.bat -DsetupFor Linux:
<PRODUCT_HOME>/bin/wso2server.sh -Dsetup
To create tables in the registry and user manager database (
WSO2CARBON_DB), execute the relevant script as shown below.mysql -u regadmin -p -Dregdb < '<PRODUCT_HOME>/dbscripts/mysql.sql';Restart the server.