question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MySQL connection not set to UTF-8?

See original GitHub issue

I believe, Ghost does not set the connection to utf8 when connecting to the MySQL server, which results in UTF-8 characters being displayed as “?” or similar characters, if the MySQL server itself is not configured to use UTF-8 as default. I am not 100% sure if this is an issue with Ghost or something else, but I’ve got the feeling that it is a Ghost problem.

I have converted my Ghost database to MySQL locally. Everything was fine there. Then I moved the database to a different server, where the characters where then interpreted wrongly.

I tripple-checked that the database and the tables used for Ghost were set to UTF-8, that the data in the tables were correctly encoded, that the output HTML page is served with UTF-8 encoding etc. Everything was as it should be.

The only difference between my local MySQL server and the production server was that in the server configuration itself the local server had all its defaults set to utf8 and the production server was set to Latin-1. Only when I changed the production MySQL server config and restarted it, the content was displayed correctly. I did not have to change anything else or re-import the tables.

Because the only way to fix this was to change the MySQL server config and any other MySQL client could read the UTF-8 encoded data correctly without the defaults being changed, I believe that Ghost doesn’t set the connection to UTF-8, something like SET NAMES utf8.

My database object in the config.js file:

database: {
    client: 'mysql',
    connection: {
        host: '...',
        port: '...',
        user: '...',
        password: '...',
        database: '...',
        charset: 'utf8'
    }
}

I could solve this issue, so that’s no personal problem for me, but I think it should always work for anybody, no matter what the MySQL default settings are. Some users may not have access to the config or must use a shared MySQL server where they can’t change the defaults.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
ErisDScommented, Jun 3, 2016

I was just re-reading this and figured I should point out, the steps above only work if your database was set to latin1 - there are other possibilities so you should check what your DB was set to before running anything like this as you could end up triple-encoding 🤐

0reactions
kirrg001commented, Mar 13, 2017

Closing. We have opened a migration path issue, which keeps track of the notes here, see #8141.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make MySQL handle UTF-8 properly - Stack Overflow
Update: Short answer - You should almost always be using the utf8mb4 charset and utf8mb4_unicode_ci collation. To alter database:
Read more >
10.4 Connection Character Sets and Collations
When the 8.0 client requests a character set of utf8mb4 , what it sends to the server is the default 8.0 utf8mb4 collation;...
Read more >
In MySQL, never use “utf8”. Use “utf8mb4”. | by Adam Hooper
Once MySQL published this invalid character set, it could never fix it: that would force every user to rebuild every database. MySQL finally...
Read more >
How to Fix the Collation and Character Set of a MySQL ...
cnf or my.ini file on your MySQL Server and you can't change this (for example utf8 is required for a database used by...
Read more >
Setting the Client Connection Character Set Properly - O'Reilly
mysql > SET NAMES 'utf8';. SET NAMES also allows the connection collation to be specified: mysql> SET NAMES 'utf8' COLLATE 'utf8_general_ci ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found