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:
Download and install MySQL on your computer using the following command:
For instructions on installing MySQL on MAC OS, go to Homebrew.
sudo apt-get install mysql-server mysql-client
Start the MySQL service using the following command:
sudo /etc/init.d/mysql start
Log in to the MySQL client as the root user (or any other user with database creation privileges).
mysql -u root -p
Enter the password when prompted.
In most systems, there is no default root password. Press the Enter key without typing anything if you have not changed the default root password.
In the MySQL command prompt, create the database using the following command:
create database regdb;
For users of Microsoft Windows, when creating the database in MySQL, it is important to specify the character set as latin1. Failure to do this may result in an error (error code: 1709) when starting your cluster. This error occurs in certain versions of MySQL (5.6.x), and is related to the UTF-8 encoding. MySQL originally used the latin1 character set by default, which stored characters in a 2-byte sequence. However, in recent versions, MySQL defaults to UTF-8 to be friendlier to international users. Hence, you must use latin1 as the character set as indicated below in the database creation commands to avoid this problem. Note that this may result in issues with non-latin characters (like Hebrew, Japanese, etc.). The database creation command should be as follows:
mysql> create database <DATABASE_NAME> character set latin1;
For users of other operating systems, the standard database creation commands will suffice. For these operating systems, the database creation command should be as follows:
mysql> create database <DATABASE_NAME>;
Give authorization to the regadmin user as follows:
GRANT ALL ON regdb.* TO regadmin@localhost IDENTIFIED BY "regadmin";
Once you have finalized the permissions, reload all the privileges by executing the following command:
FLUSH PRIVILEGES;
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>/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:
- Shut down the server and remove all existing connectors from
<PRODUCT_HOME>/lib
and<PRODUCT_HOME>/dropins
. - Download the connector JAR that is compatible with your current MySQL version.
- Copy the JAR file only to
<PRODUCT_HOME>/lib
. Files will be copied automatically to the 'dropins' folder during server startup. - Start the server with the -
Dsetup
parameter assh 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.
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.
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.