Note: You are currently viewing documentation for Moodle 2.0. Up-to-date documentation for the latest stable version is available here: Database migration Q and A.

Database migration Q and A

From MoodleDocs
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

What to backup

Q: What should be done for backup before I migrate database to utf8?

A: Just do a database export from phpMyAdmin. If you are on shared hosting then there may be time-out limit for the export process. After you have the database file say in .gz format, get the .sql file by extracting .gz file using 7 zip program (say) and see its size. Compare its size with the size mentioned in phpMyAdmin. You probably need not worry about moodledata/uploaddata folder where your other files are kept as you are not disturbing them by database utf conversion. If your database is too big and export is not working properly then you may contact your host. In moodle forums some ways are mentioned to do it using some scripts as well.

Migration script stops

Q: What to do when moodle migration script stops on its own without being killed?

A:

Option (1)

See if you can trim database. Possible tables to consider for cleaning may be the ones having log and cache text. After database trim, one can resume migration script and see the outcome.

Option (2)

  • Extract the database backup you have taken using a program like 7 zip and get the .sql file. Use Notepad or Notepad2 to open it. If it is very large, then these programs may not be able to open it. In this case LTFViewr should work. Convert the current charset, eg. latin1 to utf8 (Edit > Replace > Replace all).
  • Check if there are any utf8_swedish_ci, utf8_unicode_ci or other encodings, convert all of them to utf8_general_ci (if applicable). Note: utf8_unicode is also fine. Utf8_general works faster but is less accurate than utf8_unicode_ci.
  • Save this modified database choosing in utf-8 encoding (you will see such option in Notepad) and convert it to .gz format (7 zip program can be used).

Modified SQL file manually

Q: I used Notepad to modify the .sql file manually and saved it as .gz file finally. Now what do I do?

A:

  • Create a new database from MySQL management. Give all rights to a user setting privileges to all. Use phpMyAdmin to convert its collation to utf8_general_ci.
  • Import the modified database from phpMyAdmin. If your database is large and you are unable to import it using phpMyAdmin, then you can use bigdump.php script (just google for it).
  • Edit config.php file and change the database setting there. Also add the line $CFG->unicodedb = true; in the same file.
  • Log on to your moodle install. Check notifications and you should find no notification to migrate your database. Check you whole installation randomly.

Strange characters

Q: After editing .sql file manually using Notepad and doing all the steps mentioned finally I see some strange characters occasionally. How do I remove them. OR After trimming the database, I could run migration script but I see some strange characters occasionally. How do I remove them.

A: replace.php script may be used. It is there at ..../admin/replace.php .

Replace.php replaces only a character

Q: The replace.php script only replaces a character. I want to delete some specific characters. How do I do that?

A: replace.php script can be changed in the following manner to do this job.

Look for the line in replace.php that says

if (!data_submitted() or !$search or !$replace or !confirm_sesskey()) { /// Print a form

and remove "or !$replace".

After deleting those specific characters, one can consider removing this hack.

See also