AnsweredAssumed Answered

Working migration HSQL -> MySQL

Question asked by konradpotocki on Feb 4, 2008
Latest reply on Mar 20, 2009 by ashokkumarc
Well.. as usual the "RTFM" did not work and we started using HSQL for our Alfresco. We have decided to migrate to MySQL and realized that it's not that easy.  Export/Import was not an option: too much data (and to be honest I love challenges :+)

This small howto is loosely based on the following wiki page:
that does not work on linux MySQL (and I am not sure it will work on the windows one either, for reasons given below)

The environnement
- Alfresco 2.1/linux/tomcat
- MySQL 5/linux/compiled with UTF support (default Debian installation)

This document supposes that you are a bit familiar with MySQL. The migration takes less than one hour. If something is not clear, feel free to ask in this forum.

1. Get a windows and copy the alfresco database to your harddrive. The database is in the hsql_data directory in the Alfresco repository.

2. Install You need the "Migration Tool" so the Mac version of gui tools will not work (no M-T included)

3. Create an alfresco database. The default collation must be utf_general_ci. Create also a user with all rights for this database. This is the database that will be used by your future alfresco.

4. Run the 'MySQLMigrationTool.exe'

5. Follow the wizard steps
    * In the section Source Database use the information below:
Database System:   Generic Jdbc
Class Name:        org.hsqldb.jdbcDriver
Connection String: jdbc:hsqldb:file:<path_to_alfresco>/alf_data/hsql_data/alfresco
Username:          alfresco
Password:          alfresco
    * In the section Target Database use the information below:
Hostname: <name_of_host> - e.g. localhost
Username: <username created in step above> - e.g. alfrescohsql
Password: <password for user above>
    * If any of the information above is entered wrong the Connecting to Servers screen will report a fail.
    * In the Source Schema Selection screen, select the PUBLIC database.
    * In the Object Mapping screen, choose 'Set Parameter' for Migration of type Schema and choose 'Multilanguage'. Next, choose 'Set Parameter' for Migration of type Table and choose 'Data consistency/multilanguage'. Do not forget this step!
    * Progress through the wizard until the end, but do not migrate the data. Only create migration scripts instead. Call them create.sql (it will contain the creation instructions for the database) and insert.sql (it will contain the "insert into" statements for the actual data)

6. Unfortunately, the create.sql script is useless for two reasons:
* The tables are all created with names in capital letters and MySQL on a case sensitive filesystem (as any Linux fs) is case sensitive in table names.
* The created tables does not contain all the needed parameters: namely default values for some fields.
The solution to this problem is to make alfresco create its own database by itself. (we will use a fake repository directory for that)

7. Edit 2 files in alfresco
(change the dialect from HSQL to MySQL)
(change all the db.* values in order to match your MySQL created database and put some existing empty directory in the dir.root line)

8. Launch Alfresco and observe the logs (tomcat/logs/catalina.out). You will see that it launches the MySQL InnoDB driver and it fills your new database with tables and data.

9. When Alfresco is up, just stop it. You can once again modify
to make it point to your production repository (dir.root line).

10. Empty the database Alfresco just created. Leave empty tables (just "TRUNCATE" them). You must desactivate foreign keys or truncate tables in the correct order.

11. Open the insert.sql file from point 5 with your favorite UTF-8 compatible text editor. Do 2 things:
* Edit all the lines "INSERT INTO…" and change the table names to lowercase. Do it for all tables except for the tables starting with JBPM (so do it for tables starting from alf_ and _avm_ if they exist).
* By default, all the inserts are to the "public" database and not to the active one. The solution is to replace the string `public`. (with ` and the dot) with an empty one.

12. Launch the resulting inserts.sql against your database. Either use phpmyadmin or the mysql command line.

13. Finish your coffee, launch alfresco and look at the logs to be sure that all is well…

It worked very well for me and as far as I can say, there is no risk in this process. Hope it helps :+)