Importing MyBB to Discourse

In this tutorial, we will learn how to migrate MyBB forum to :discourse: platform using the official MyBB Importer script.

What can be migrated

  • Categories
    • Root category => root category
    • Child category => sub category
    • Root Forum => sub category
    • child forum => sub category
  • Threads & replies => topics & posts
  • Users
    • username
    • email
    • privilege status
    • joining status
  • Redirects

Our plan is very simple:

  • Setup the local DEV environment.
  • Exporting the production database.
  • Importing the production database to Discourse.
  • Running MyBB importer script.

Let’s get started :slightly_smiling_face:

Setup The Local DEV Environment

First of all, you need to follow one of these guides to install Discourse platform itself. Consult this guide if you have any problems.

Install MySQL database server;


$ brew install mysql@5.7
$ echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile

Check the service status:

$ brew services list

You should see something like this:

mysql@5.7         started

Otherwise, run the following and try again:

$ brew services start mysql@5.7

Ubuntu 18.04:

$ sudo apt update
$ sudo apt install mysql-server -y

After finishing installing MySQL, check its status:

$ systemctl status mysql.service

If it’s not running, run the following:

$ sudo systemctl start mysql

For Windows, you can follow the official installation guide

We will call this environment: Discourse server.

Exporting The Production Database

Export/Backup the production database (from MyBB production server) by running:

$ mysqldump -u USER_NAME -p DATABASE_NAME > mybb_dump.sql
  • Copy this database dump to the Discourse server.

:bulb: You can use scp or rsync to copy the database.

Importing The Production Database to Discourse

On Discourse server, Create a database:

$ mysql -u root

:bulb: If your DB user has a password, you should use: mysql -u root -p then type your password.

mysql> CREATE DATABASE mybb;

Make sure that the database has been created successfully by running:


You should see something like:

| Database           |
| information_schema |
| mysql              |
| performance_schema |
| mybb               |
| sys                |

The mybb DB is empty by now. Our next step is to import the production database into it.

$ mysql -u root mybb < mybb_dump.sql

Later, we will need the table prefix. So, While we are here, let’s get it.

$ mysql -u root
mysql> USE mybb;

You will see something like this:

| Tables_in_mybb           |
| mybb_adminlog            |
| mybb_adminoptions        |
| mybb_adminsessions       |
| mybb_adminviews          |
| mybb_announcements       |
| mybb_attachments         |
| mybb_attachtypes         |
| ...The rest of tables....|

Our table prefix is mybb_ as the output shows.

Running MyBB Importer Script

  • Let’s first install the importer dependencies. From Discourse server:
$ cd ~/discourse
$ echo "gem 'mysql2', require: false" >> Gemfile
$ bundle install

Next, you should configure the script to run properly. Copy and paste the following into your shell (change the values if necessary):

export DB_HOST="localhost"
export DB_NAME="mybb"
export DB_PW=""
export DB_USER="root"
export TABLE_PREFIX="mybb_"

You have other option to configure the script. Open script/import_scripts/mybb.rb in any editor of your choice and change the values inside the double quotation to fits your needs:

  DB_HOST ||= ENV['DB_HOST'] || "localhost"
  DB_NAME ||= ENV['DB_NAME'] || "mybb"
  DB_PW ||= ENV['DB_PW'] || ""
  DB_USER ||= ENV['DB_USER'] || "root"

Run the importer with a clean Discourse instance:

$ bundle exec rails db:drop
$ bundle exec rails db:create
$ bundle exec rails db:migrate
$ bundle exec ruby script/import_scripts/mybb.rb

The importer will connect to MySQL server and migrates your MyBB database to Discourse database.

After the importer finish, start Discourse instance by running:

$ bundle exec rails server

Next, start Sidekiq (background jobs processor) to process the migrated data:

$ bundle exec sidekiq

:bulb: You can monitor sidekiq progress at http://localhost:3000/sidekiq/queues.

Setup your Discourse production server by following this tutorial.

Perform a backup for Discourse platform (local Discourse Server) and upload it to your Discourse production server by following this tutorial.


If you have any questions about the process I am happy to help.

Happy migration :grinning:


Hi - this looks like a great guide, except as a Cpanel rather than linux user, migrating from a shared host, I don’t have root access or ssh access to the original host, but I do have access to PhPMyAdmin in Cpanel from which I can export the Mybb database.
Will this do?
What if any special export settings are required? And into what directory on my Digital Ocean droplet should this database be copied? (I am using FileZilla)


It does not matter, home directory works just fine.


Hi again - I can get up to this point in the tutorial

bundle install

and for me this falls over with error

'Don’t run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Your Gemfile has no gem server sources. If you need gems that are not already on
your machine, add a line like this to your Gemfile:
source ‘
Could not find gem ‘mysql2’ in any of the gem sources listed in your Gemfile.

Any suggestions?

Unfortunately I know nothing about ruby or linux or gemfiles and so am just literally plodding though various discourse cli setup tasks as the tutorials instruct by cutting and pasting commands via PuTTy, without any kind of understanding.

I am running Ubuntu and Discourse in a Digital Oceans Droplet, if that helps?

Also, I see a subsequent reference to pasting database export commands into ‘shell’ . For practical purposes is my current PuTTy connection to the server = ‘shell’, or is some other interface/console involved?

OK, in partial answer to my own question, random thrashing around on forums suggests

$ sudo apt-get install libmysqlclient-dev

will then allow mysql2 gem to install (whatever that is) - ignoring the warning about not doing this as root.

Getting past that and to the next step - typing

$ bundle exec rails db:drop

gives another error::::

bundler: failed to load command: rails (/usr/local/bin/rails)
Gem::Exception: can’t find executable rails for gem railties. railties is not currently included in the bundle, perhaps you meant to add it to your Gemfile?

Checking in /usr/local/bin/ and I can see a file named ‘rails’ is definitely there.

Typing $ sudo gem or $ gem install rails or $ sudo gem install rails does not help (per various suggestions stumbled across for this error).

Have even gone back and installed Ruby on Rails from scratch to try and ensure all normal dependencies are present How To Install Ruby on Rails with rbenv on Ubuntu 18.04 | DigitalOcean -and no improvement - whether I use version 2.51 or 2.61.

Well out of my depth here…

Well I can say categorically that following this guide as written does NOT work for anyone following the official steps for setting up local Dev environment under WSL2 installation of Ubuntu-18.04 under Windows 10 - at almost every step there will be some dependency missing or connection refused error or similar.

With a lot of pain and online research, I have managed to get up to the command:

$ bundle exec ruby script/import_scripts/mybb.rb

but this generates response:

mysql2/client.rb:90:in `connect’: Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) (Mysql2::Error::ConnectionError)

This has been a brick wall - nothing I have found by searching online seems to offers a working solution to this

How do I solve this and progress to the next step? Any help much appreciated!

1 Like

Hi, how can I upload database on my DigitalOcean droplet? I used installation 1click of DigitalOcean to install Discourse (Ubuntu).
On my PC I have Windows 10 Home 18362 build version.

Then I have installed Mysql but now I don’t know how “physically” upload Mybb database on the server. Isn’t there phpmyadmin where you can easily import the database? :frowning:

1 Like

You need to upload the file using scp or similar. Then Something like

  mysql - u user - p password database < filename..sql

I’m stuck :frowning:

1 Like

This guide should be updated to be compatible with running the import inside a Docker install instead of using a local development machine.


Really looking forward for the guide to run on a docker based environment :slight_smile:

1 Like

I gave up on DIY in the end and got a developer on the job - referring him to all the great suggestions on this forum (which helped!) - and I believe he achieved this directly on my live Digital Ocean droplet rather than in a separate development environment (so I could review things easily as he worked - users were not impacted as forum not officially live yet.) - in other words I think it is possible.

After a few iterations, results are now pretty good - all the MyCode and strange character issues resolved, translated my MyBB post prefixes as Discourse tags, custom multi-select user profile fields imported successfully.

If he is willing, I will ask him to share any tweaks to standard import script, and other techniques used here.