Configuring MariaDB
MariaDB is a community-developed fork of MySQL, created due to concerns about Oracle’s acquisition of MySQL and led by the original MySQL developers. It remains free under the GNU GPL.
MariaDB has supported database sequences since v10.3, but we recommend using v10.6 or newer right now. See MariaDB Server Releases.
Preliminaries
Section titled “Preliminaries”Check if your MariaDB installation has the InnoDB engine enabled:
$ mariadb -h localhost -u root -p> show engines;If another default engine is in use, you must change the default engine to InnoDB, since it is the only engine supported by the current com.openkm.db.dialect.MariaDBDialect dialect.
Change default engine
Section titled “Change default engine”Modify the MariaDB configuration file named my.cnf
Then, under [mysqld], add
default-storage-engine = innodb
Change default charset
Section titled “Change default charset”In Ubuntu 16.04, the default charset configured in MariaDB is utf8mb4, but we recommend switching to utf8. To get the recommended charset, you have to modify these files:
/etc/mysql/mariadb.conf.d/50-server.cnf
character-set-server = utf8collation-server = utf8_general_ci/etc/mysql/mariadb.conf.d/50-client.cnf
default-character-set = utf8/etc/mysql/mariadb.conf.d/50-MySQL-clients.cnf
default-character-set = utf8Once modified, you need to restart the database server.
Database creation
Section titled “Database creation”Create a database and user
Section titled “Create a database and user”DROP DATABASE IF EXISTS okmdb;CREATE DATABASE okmdb DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin;CREATE USER openkm@localhost IDENTIFIED BY '*secret*';GRANT ALL ON okmdb.* TO openkm@localhost WITH GRANT OPTION;You can check the database engine with the following:
$ mariadb-show -h localhost -u root -p --status okmdb;More information at MySQL: Case Sensitivity in String Searches
Create a database in Persian
Section titled “Create a database in Persian”Set Persian collation and character set in the my.ini configuration file (requires restarting the service):
collation_server = utf8mb4_persian_cicharacter_set_server = utf8mb4Set Persian collation and character set in the current MariaDB session (after restarting the service, the default values from my.ini will be used):
SET collation_server = 'utf8mb4_persian_ci';SET character_set_server = 'utf8mb4';Database:
CREATE DATABASE okmdb CHARACTER SET utf8mb4 COLLATE utf8mb4_persian_ci;CREATE USER openkm@localhost IDENTIFIED BY 'k4M0j4lBi#ed';GRANT ALL ON okmdb.* TO openkm@localhost WITH GRANT OPTION;Configure your openkm.properties
Section titled “Configure your openkm.properties”Edit the file $TOMCAT_HOME/openkm.properties
spring.jpa.hibernate.ddl-auto=create-onlyspring.jpa.properties.hibernate.dialect=com.openkm.db.dialect.MariaDBDialectConfigure Tomcat data sources
Section titled “Configure Tomcat data sources”Edit the file $TOMCAT_HOME/openkm.properties and enable the resource named JDBC/OpenKMDS
spring.datasource.driver-class-name=org.mariadb.jdbc.Driverspring.datasource.url=jdbc:mariadb://localhost:3306/okmdb?autoReconnect=true&useUnicode=true&characterEncoding=UTF8&nullNamePatternMatchesAll=true&serverTimezone=Europe/Madridspring.datasource.username=openkmspring.datasource.password=*secret*Configure application login
Section titled “Configure application login”Edit the file $TOMCAT_HOME/openkm.properties
authentication.openkm.database=trueRun application
Section titled “Run application”At OpenKM startup, the application will automatically create an empty database structure.
Migrate from Windows to Linux
Section titled “Migrate from Windows to Linux”When you migrate from Windows to Linux, you must convert lowercase table names to uppercase. The following script will help with it:
select concat('rename table ', table_name, ' to ' , upper(table_name) , ';') from information_schema.tables where table_schema = 'okmdb';Case-insensitive node names
Section titled “Case-insensitive node names”By default, the database is case sensitive. However, by executing:
ALTER TABLE OKM_NODE_BASE MODIFY NBS_NAME varchar(256) COLLATE utf8mb3_general_ci;the NBS_NAME column is modified so that node names are treated in a case-insensitive manner. This collation also ignores accent differences, so names with and without accents are considered equivalent.
As a consequence, it will not be possible to have two documents such as “Más temas.txt” and “mas temas.txt”, since for the table index they are interpreted as the same string and the uniqueness constraint will fail.
If this happens, the system may throw an error like:
ERROR 1062 (23000): Duplicate entry '483ab139-9c20-44a9-8534-ed124a8f37ba-NULL' for key 'IDX_NODE_BASE_PARNAM'This means both values are considered identical and the unique index detects them as duplicates.
To identify problematic nodes, you can run the following query:
SELECT NBS_PARENT, NBS_NAME, COUNT(*) FROM OKM_NODE_BASEGROUP BY NBS_PARENT, LOWER(NBS_NAME) HAVING COUNT(*) > 1;Any duplicates found should be renamed so they stop being treated as equal.
Troubleshooting
Section titled “Troubleshooting”Error “ASCII ‘\\0’ appeared in the statement” when importing a database dump.
Section titled “Error “ASCII ‘\\0’ appeared in the statement” when importing a database dump.”It is possible that the error is caused by the encoding of the SQL file. You should check the file format. For example, with the command:
> file okmdb.sqlokmdb.sql: Little-endian UTF-16 Unicode text, with very long lines, with CRLF line terminatorsIf the file is in UTF-16 format, convert it to UTF-8. For example, use the command:
> iconv -f utf-16 -t utf-8 okmdb.sql > okmdb-good.sql