# Imported MyBB database character encoding issue

**URL:** https://meta.discourse.org/t/imported-mybb-database-character-encoding-issue/144156
**Category:** Migration
**Tags:** mybb
**Created:** [March 12, 2020, 11:37pm UTC](https://meta.discourse.org/t/imported-mybb-database-character-encoding-issue/144156 "2020-03-12T23:37:48Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Paul\_King](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paul_king/32/165426_2.png) [@Paul\_King](https://meta.discourse.org/u/Paul_King)
#### Post date: [March 12, 2020, 11:37pm UTC](https://meta.discourse.org/t/imported-mybb-database-character-encoding-issue/144156/1 "2020-03-12T23:37:48Z")

</div>

Hi, I have a bunch of posts and even usernames imported from a MyBB forum that are displaying random characters like â€™ and Â

From what I can glean from reports of similar behavior in WordPress, this may be a Latin1 vs UTF8 encoding issue?

Is there an easy way to remove these after the fact?

What do the characters actually relate to? - I can’t think what original characters they might have been substituted for.

Also I see some imported posts contain a bunch of un-parsed MyCode - is there a way for this to be parsed in Discourse?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 13, 2020, 12:17am UTC](https://meta.discourse.org/t/imported-mybb-database-character-encoding-issue/144156/2 "2020-03-13T00:17:27Z")

</div>

> [@Paul\_King](#):
>
> From what I can glean from reports of similar behavior in WordPress, this may be a Latin1 vs UTF8 encoding issue?

Yes. That’s my guess. I’m working with an import now with similar problems. Most of them are things like curly quotes and emdashes.

> [@Paul\_King](#):
>
> Is there an easy way to remove these after the fact?

It’s far from easy, but you you can do some post-processing that either does a `force_encoding` or attempts to replace the characters one-by-one.

Something like

```plaintext
Post.all.each do |post|
  post.raw = post.raw.force_encoding('utf-8').encode("Windows-1252").force_encoding('utf-8')
  post.save!
  post.rebake!
end

```

But I’d test it extensively on a staging site before you run it on your live data.

---

<div class="post-metadata">

### Author: ![Paul\_King](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paul_king/32/165426_2.png) [@Paul\_King](https://meta.discourse.org/u/Paul_King)
#### Post date: [March 13, 2020, 2:39am UTC](https://meta.discourse.org/t/imported-mybb-database-character-encoding-issue/144156/3 "2020-03-13T02:39:16Z")

</div>

Thanks Jay.  
Is there any clever way of dealing with the issue at source - i.e re-exporting database from old forum, then re importing free of characters and mycode issues?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 13, 2020, 3:09am UTC](https://meta.discourse.org/t/imported-mybb-database-character-encoding-issue/144156/4 "2020-03-13T03:09:58Z")

</div>

If you’ve not gone live so that starting over isn’t an option, That’s the best way to do it.

---

<div class="post-metadata">

### Author: ![Paul\_King](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paul_king/32/165426_2.png) [@Paul\_King](https://meta.discourse.org/u/Paul_King)
#### Post date: [March 13, 2020, 3:18am UTC](https://meta.discourse.org/t/imported-mybb-database-character-encoding-issue/144156/5 "2020-03-13T03:18:21Z")

</div>

Site is not officially live - but what is best way to deal with character issues and mycode parsing when exporting from MyBB?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [March 13, 2020, 3:32am UTC](https://meta.discourse.org/t/imported-mybb-database-character-encoding-issue/144156/6 "2020-03-13T03:32:01Z")

</div>

Exporting all data in UTF-8, if possible, will solve those issues.

---

<div class="post-metadata">

### Author: ![Paul\_King](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paul_king/32/165426_2.png) [@Paul\_King](https://meta.discourse.org/u/Paul_King)
#### Post date: [March 13, 2020, 4:54am UTC](https://meta.discourse.org/t/imported-mybb-database-character-encoding-issue/144156/7 "2020-03-13T04:54:21Z")

</div>

I went back to original MyBB installation, and found in admin control panel/Tools and Maintenance/System Health a warning

> It is recommend not to use different encodings in your database. This may cause unexpected behavior or MySQL errors.

The tables are listed, and I could see most but not all were in UTF-8 format. Looked like some, particularly associated with plugins, were in an older format

Clicking a ‘Convert all’ link brought up response that /inc/config.php needed editing to support full 4 byte UTF-8

> $config[‘database’][‘encoding’] = ‘utf8mb4’;

After editing config.php and trying the conversion again, all now show as matching. Will try re importing to Discourse and report back if this helps with character issues.

Not sure still how to deal with MyCode parsing though?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [March 13, 2020, 5:08am UTC](https://meta.discourse.org/t/imported-mybb-database-character-encoding-issue/144156/8 "2020-03-13T05:08:53Z")

</div>

> [@Paul\_King](#):
>
> Not sure still how to deal with MyCode parsing though?

You didn’t include any examples or details of this - at this point, may be best to start a new thread and keep this one focused on the followup for the character encoding.

---

<div class="post-metadata">

### Author: ![Paul\_King](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paul_king/32/165426_2.png) [@Paul\_King](https://meta.discourse.org/u/Paul_King)
#### Post date: [March 13, 2020, 9:56am UTC](https://meta.discourse.org/t/imported-mybb-database-character-encoding-issue/144156/9 "2020-03-13T09:56:25Z")

</div>

Hi, a new thread with an example is [here](https://meta.discourse.org/t/imported-mybb-database-mycode-issue/144173)
