Importing / migrating 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;

MacOS:

$ 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:

mysql> SHOW DATABASES;

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;
mysql> SHOW TABLES;

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"
  TABLE_PREFIX ||= ENV['TABLE_PREFIX'] || "mybb_"

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.

:tada:

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

Happy migration :grinning:

7 Likes

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)

Yes.

It does not matter, home directory works just fine.

3 Likes

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 ‘https://rubygems.org
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
3 Likes

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.

4 Likes

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

2 Likes

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.

4 Likes

In case it helps anyone, the developer @rahilqf I engaged completed the project including translation of custom MyBB user fields into Discourse custom user fields (which depends on having the multi-select-user-field plugin installed), MyBB post prefixes translated into Discourse tags, and stripping out of nearly all redundant MyCode tags from MyBB post text.

His customized import script version is shared here - Custom MyBB to Discourse Import Script.

He also successfully merged in a Yahoo Groups Mbox archive, using the standard Yahoo import script - though with this attachments seemed not to translate. In my case that was not a major problem.

3 Likes

I’m converting users, post, topics etc from Mybb database!

I have followed this guide: Beginners Guide to Install Discourse on Ubuntu for Development

but http://localhost:3000/ or http://forum.omaggieconcorsi.com:3000/ don’t work

Anyway, the program is converting something, but I don’t know where I can then export the data.
Discourse I can’t see it with http://forum.omaggieconcorsi.com:3000/ or http://localhost:3000/ so how can I at least export the database with posts, users etc. from the old Mybb forum and then import it on new Discourse instance?

Thanks!

Did you follow those instructions on the same computer where you’re running the web browser?

1 Like

Yes, always the same computer

Ok, I have followed this guide on Ubuntu 18.04 “real” SO installed on PC and localhost:3000 works!

But now I have problem with database Mysql :frowning: Sorry…

I type:

debby@debby-MS-7721: mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

:frowning:

EDIT: I have added password to root with ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

And in DB_PW I have written the password of root user.

… and now it’s creating users!!

Cross your fingers for me, is it finally the right time after weeks of testing??

1 Like

I’m trying to import the database from MyBB to discourse. Like @Paul_King I can’t get it to work on my DigitalOcean server. I keep getting all kinds of errors as I follow this guide.

I’m stuck trying to execute the command

$ bundle exec rails db:drop
bundler: command not found: rails
Install missing gem executables with `bundle install`

Bundle install says it’s complete

$ bundle install
Your Gemfile lists the gem mysql2 (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of one of them later.
Using bundler 1.16.1
Using mysql2 0.4.10
Bundle complete! 2 Gemfile dependencies, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

Trying to manually install rails results in this:

$ gem install rails
Building native extensions. This could take a while...
ERROR:  Error installing rails:
        ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.5.0/gems/racc-1.5.2/ext/racc/cparse
/usr/bin/ruby2.5 -r ./siteconf20210110-8155-1ms05r3.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.5.0/gems/racc-1.5.2 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/racc-1.5.2/gem_make.out

This is extremely frustrating.


Left this post open and managed to install rails. Then had a million other errors and managed to fix them. Errors. On. Every. Single. Step.

Never before I have felt such pure hatred for software. Why is ruby like this? This is a nightmare. I’m now stuck with this error:

$ bundle exec rails db:drop
Traceback (most recent call last):
        1: from /usr/local/bin/bundle:23:in `<main>'
/usr/local/bin/bundle:23:in `load': cannot load such file -- /usr/share/rubygems-integration/all/gems/bundler-1.16.1/exe/bundle (LoadError)

Can someone help?

1 Like

Not useful, but I encountered much the same brick walls, both when attempting to set up in a local development environment (to generate a Discourse database file/backup) and directly in my Digital Ocean Droplet. Finally decided after wasting tens of hours that life is too short and got a developer from Fiverr (who took weeks to figure it out, but got there).
I suspect the incentives just aren’t there for anyone to make the process easier.

Best of luck - and I hope if you finally do crack it, you will leave a trail of breadcrumbs on here for others to follow!

1 Like

How did you install rails? Did you usual one of the development guides? (like Beginners Guide to Install Discourse on Ubuntu for Development)

There are some howto documents for running the install script inside the production container (what I usually do), so you might use one of those for a guide.