By default Senzing is set to use an embedded SQLite database. This article describes the steps to configure Senzing to use MySQL as the entity repository and how to create the Senzing schema within a MySQL database.
This article assumes you are already a MySQL user or familiar with MySQL, it only briefly covers the installation steps of MySQL. If you require additional MySQL information the following links will be useful:-
In addition to the dependencies outlined in the Introduction: Quickstart article the following operating system prerequisites and packages are required. You must ensure the dependencies in the quickstart article are met before proceeding.
- sudo or root privileges to install MySQL and issue system commands
sudo apt install unixodbc unixodbc-dev
sudo apt install python-pyodbc
Install and Basic MySQL Setup
The following is a brief overview of the steps required to install MySQL. For full details on installing MySQL on Linux please see Installing, and Upgrading MySQL.
Download the repository installation package directly from the apt repository website or with the wget command.
- MySQL apt Repository
- Locate the Ubuntu/Debian package
- Select Download
- If you don't have a MySQL account choose "No thanks, just start my download."
- On the MySQL apt Repository website locate the Ubuntu / Debian package and then the package name in brackets under the title
- Use wget with this name string to directly download the package
- Once downloaded add the repository information by installing the package, and then installing MySQL.
sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb
- Select OK
sudo apt update
sudo apt install mysql-community-server
sudo apt install libmysqlclient21
- Start MySQL and check the status
sudo systemctl start mysql
sudo systemctl status mysql
- If started successfully you will see output similar to the following
- MySQL will autostart at system boot, if you'd like to disable autostarting issue
sudo systemctl disable mysql
- It is highly recommended to harden security settings.
- Answer 'Y' to all questions (unless your organization's policies differ)
- During MySQL installation you would have set your root user password, you can skip changing it during this step
- Test connection and setup G2 user. Check the following permissions meet your organisations policies. The user name 'g2' is used in the following example, change as appropriate to the user id your G2 installation is run under
mysql -u root -p
- You will be prompted for your new root password
create user 'g2'@'%' identified by '<g2_user_password>';
- Change <g2_user_password> to your desired password to access MySQL
- Password must be at least 12 chars, one upper, one lower, one number and one special character
grant all privileges on G2.* to 'g2'@'%';
grant all privileges on G2_REPORT.* to 'g2'@'%';
- Test the new g2 user and create the G2 databases
mysql -u g2 -p
- You will be prompted for the password you used for <g2_user_password>
create database G2 character set=utf8 collate=utf8_bin;
create database G2_REPORT character set=utf8 collate=utf8_bin;
Add Senzing Schemas to MySQL
- Core Schema
mysql -u g2 -p G2 < /opt/senzing/g2/data/g2core-schema-mysql-create.sql
- Report Schema
mysql -u g2 -p G2_REPORT < /opt/senzing/g2/data/report_schema_mysql-create.sql
- g2 = User id previously used in above commands, substitute your user id if different
- -p = Will prompt for the password you used for <g2_user_password>
- /opt/senzing/g2/... = Default Senzing deployment directory
Configure and Test ODBC
Download the MySQL ODBC connectors
- Select the Operating System 'Debian Linux'
- Choose OS Version (probably 64-bit)
- If you want to use wget to download instead, follow the directions above for downloading MySQL with wget and substitute the URL and file name to point to the MySQL ODBC connector - e.g., https://dev.mysql.com/get/Downloads/Connector-ODBC/8.0/mysql-connector-odbc-8.0.12-linux-debian9-x86-64bit.tar.gz
Once downloaded install the ODBC connector
tar xvf mysql-connector-odbc-8.0.12-linux-debian9-x86-64bit.tar.gz
sudo cp bin/* /usr/local/bin/
sudo cp lib/* /usr/local/lib/
sudo myodbc-installer -a -d -n "MySQL ODBC 8.0 Unicode Driver" -t "Driver=/usr/local/lib/libmyodbc8w.so"
sudo myodbc-installer -a -d -n "MySQL ODBC 8.0" -t "Driver=/usr/local/lib/libmyodbc8a.so"
Once installed, add the following entries to /etc/odbc.ini, you need to edit the file with root/sudo privileges.
Driver = MYSQL
Database = G2
Server = 127.0.0.1
Port = 3306
Driver = MYSQL
Database = G2_REPORT
Server = 127.0.0.1
Port = 3306
Modify /etc/odbcinst.ini (also with root/sudo) and comment out the stanza header for [MySQL ODBC 8.0 Unicode Driver] and add the [MYSQL] header. If you already have a [MYSQL] stanza section are not using it (from an old driver) you can comment out the entire old [MYSQL] section.
#[MySQL ODBC 8.0 Unicode Driver]
Test ODBC is working with MySQL against the G2 database, you should see a result set of count =0 from the SQL select statement.
isql -v G2 g2 <user_password>
select count(*) from OBS_ENT;
Configure G2Project.ini and G2Module.ini
Modify the following ini files to reference the new MySQL databases and schemas. These files are located in /opt/senzing/g2/python (if you've not altered the default location). You can comment out the current lines by prefixing them with # and adding the modified ones below.
- G2Project.ini - Change the G2Connection and ODSConnection strings to
- G2Module.ini - Change the CONNECTION string to
- g2 = G2 userid
- password4g2 = Password for the G2 userid
- 127.0.0.1 = G2 server address
- 3306 = MySQL port number
Run a Test G2 Load and G2 Report
Perform a test load of the supplied sample data and then perform a G2 report creation to test the new database setup.
- Source setupEnv
- Load the G2 sample data
python G2Loader.py -P -p demo/sample/project.csv
- Create the g2report file