How to Fix the Collation and Character Set of a MySQL Database

By | 8. May 2019

Recently I came across with issue where migrating website from one hosting to another resulted on text encoding issues. Site was very old and lot of time had passed, so on new server all texts coming from database had cryptic signs instead of Nordic characters.

All you can find below is from article on page https://confluence.atlassian.com/kb/how-to-fix-the-collation-and-character-set-of-a-mysql-database-744326173.html

Very often once found source is hard to find next time, so this blog servers also as bookmarking for me 🙂

So in short what helped me was:

 

Changing the Database Collation

Change  yourDB to suit your database name:

[/crayon]

Changing Table Collation

The following query will produce a series of  ALTER TABLE statements, which you must then run against your database. Change  yourDB to suit your database name:

[/crayon]

Changing Column Collation

The following queries (one for  varchar columns, and one for non- varchar columns) will produce a series of  ALTER TABLE statements, which you must then run against your database. Change  yourDB to suit your database name:

[/crayon]
[/crayon]

In addition (this was not needed in my case)

Dealing with Foreign Key Constraints

It may be necessary to ignore foreign key constraints when making changes to a large number of columns. You can use the  SET FOREIGN_KEY_CHECKS command to ignore foreign key constraints while you update the database.

[/crayon]

 

Once more big thanks to article author(s)

Next time we will have look what had to be done with text files what were also in wrong encoding and php scripts what had to be migrated from using mysql library to mysqli.

 

 

One thought on “How to Fix the Collation and Character Set of a MySQL Database

  1. Pingback: Convert files encoding ASCII with special character to UTF-8 file - Software Blog

Leave a Reply