Migrate From SQLite to MySQL

NOTE: The tutorial is only available for Seafile CE version.

First make sure the python module for MySQL is installed. On Ubuntu, use sudo apt-get install python-mysqldb to install it.

Steps to migrate Seafile from SQLite to MySQL:

  1. Stop Seafile and Seahub.

  2. Download sqlite_to_mysql.sh to the top directory of your Seafile installation path. For example, /data/haiwen.

  3. Run sqlite_to_mysql.sh, this script will produce three files (ccnet_db_data.sql, seafile_db_data.sql, seahub_db_data.sql).

    1. chmod +x sqlite_to_mysql.sh
    2. ./sqlite_to_mysql.sh
  4. Download these three files to /data/haiwen, ce_ccnet_db.sql, ce_seafile_db.sql, mysql.sql(used for create tables in seahub_db).

  5. Rename mysql.sql to ce_seahub_db.sql: mv mysql.sql ce_seahub_db.sql. Now you should have the following directory layout.

    1. .
    2. └── haiwen
    3. | ...
    4. | ...
    5. | ├── ce_ccnet_db.sql
    6. | ├── ce_seafile_db.sql
    7. | ├── ce_seahub_db.sql
    8. | ├── ccnet_db_data.sql
    9. | ├── seafile_db_data.sql
    10. | ├── seahub_db_data.sql
    11. | ...
    12. | ├── seafile-data
    13. | ├── seahub-data
    14. | ├── seahub.db
    15. | ...
    16. | ...
  6. Create 3 databases ccnet_db, seafile_db, seahub_db and seafile user.

    1. mysql> create database ccnet_db character set = 'utf8';
    2. mysql> create database seafile_db character set = 'utf8';
    3. mysql> create database seahub_db character set = 'utf8';
  7. Import ccnet data to MySql.

    1. mysql> use ccnet_db;
    2. mysql> source ce_ccnet_db.sql;
    3. mysql> source ccnet_db_data.sql;
  8. Import seafile data to MySql.

    1. mysql> use seafile_db;
    2. mysql> source ce_seafile_db.sql;
    3. mysql> source seafile_db_data.sql;
  9. Import seahub data to MySql.

    1. mysql> use seahub_db;
    2. mysql> source ce_seahub_db.sql;
    3. mysql> source seahub_db_data.sql;
  10. Modify configure files.

    Append following lines to ccnet.conf:

    1. [Database]
    2. ENGINE=mysql
    3. HOST=127.0.0.1
    4. USER=root
    5. PASSWD=root
    6. DB=ccnet_db
    7. CONNECTION_CHARSET=utf8

    Note: Use 127.0.0.1, don’t use localhost.

    Replace the database section in seafile.conf with following lines:

    1. [database]
    2. type=mysql
    3. host=127.0.0.1
    4. user=root
    5. password=root
    6. db_name=seafile_db
    7. connection_charset=utf8

    Append following lines to seahub_settings.py:

    1. DATABASES = {
    2. 'default': {
    3. 'ENGINE': 'django.db.backends.mysql',
    4. 'USER' : 'root',
    5. 'PASSWORD' : 'root',
    6. 'NAME' : 'seahub_db',
    7. 'HOST' : '127.0.0.1',
    8. # This is only needed for MySQL older than 5.5.5.
    9. # For MySQL newer than 5.5.5 INNODB is the default already.
    10. 'OPTIONS': {
    11. "init_command": "SET storage_engine=INNODB",
    12. }
    13. }
    14. }
  11. Restart seafile and seahub

NOTE

User notifications will be cleared during migration due to the slight difference between MySQL and SQLite, if you only see the busy icon when click the notitfications button beside your avatar, please remove user_notitfications table manually by:

  1. use seahub_db;
  2. delete from notifications_usernotification;