Use an import script that requires MySQL

A bbpress install is quite standard. A wordpress database and all posts inside wp_posts. So all I need is to dump the Wordpress posts database ?
Sorry to ask but I didn’t find any other instructions.

Thank you

You can either get a dump of the entire wordpress database or you can read the code and see what tables are actually used. It’s easier to dump the whole database.

Whether you do that with mysqump or cpanel or phpmtadmin or some other tool is hard make a recommendation for.

It works (after few tweaks) :slight_smile: :slight_smile: Thank you :wink:

1 Like

I have connection error to the MySQL DB when importing. SQL Db is in localhost. How do I get past this error?

/var/www/discourse# su discourse -c “bundle exec ruby script/import_scripts/bbpress.rb”

/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect’: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) (Mysql2::Error::ConnectionError)


If the mysql server is running on the server and not in the container then try using the host ip number

MySQL is running in a container where discourse is also running. Looks like import script from the discourse container is unable to connect to MySQL container. What else can I do?

Are you sure? Can you connect to it with the mysql command line tool from within the container?

1 Like

I got pas that issue. I was using localhost, then I figured the IP address for MySQL should be from ```
docker inspect mysql | grep IPAddress.

Next Issue with Import Script.. 

/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect': Plugin caching_sha2_password could not be loaded: /usr/lib/x86_64-linux-gnu/mariadb19/plugin/ cannot open shared object file: No such file or directory (Mysql2::Error::ConnectionError)

I did use ALTER command to change the password.

Solution to above issue - Ran the following command again.

ALTER USER 'root' IDENTIFIED WITH mysql_native_password BY 'newpassword';
1 Like

After using some of the various fixes posted above for issues running the importer, I’m not seeing any posts actually import. Any thoughts why I would get a successful connection to the new database only to have no posts import?

I’m attempting to import a few hundred posts on a non-bbPress WordPress (5.7) site into an already running Discourse site with a few hundred posts (2.7.0-beta5).

Imported DB appears to exist:

mysql> show tables;
| wp_commentmeta        |
| wp_comments           |
| wp_links              |
| wp_options            |
| wp_postmeta           |
| wp_posts              |
| wp_term_relationships |
| wp_term_taxonomy      |
| wp_termmeta           |
| wp_terms              |
| wp_usermeta           |
| wp_users              |
Output when running the importer:
/var/www/discourse# su discourse -c "bundle exec ruby script/import_scripts/bbpress.rb"
Loading existing groups...
Loading existing users...
Loading existing categories...
Loading existing posts...
Loading existing topics...

importing users...

importing anonymous users...

importing categories...

importing topics and posts...

Importing attachments from 'postmeta'...

creating permalinks...

Updating topic status

Updating bumped_at on topics

Updating last posted at on users

Updating last seen at on users

Updating first_post_created_at...

Updating user post_count...

Updating user topic_count...

Updating user digest_attempted_at...

Updating topic users

Updating post timings

Updating featured topic users

Updating featured topics in categories
        6 / 6 (100.0%)  [1771 items/min]  ]  
Resetting topic counters

Done (00h 00min 00sec)

You’ll need to modify the script to import the data. The bbpress script imports only posts of a particular type (I likely don’t remember the right wordpress lingo). What kind of WP posts do you want to import? Which are topics and which are posts? Is there something like categories? Those are just a few questions you’ll need to answer by modifying the script. How to do that is beyond the scope of the support you’re likely to get here.

Edit:I’ve retired a few times and gotten closer… Now:

At step 2, mysql -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE < /backup/yourbackup.sql i get the error bash: /backups/yourstratapropertywordpress.sql: No such file or directory when it does exist (at least, in /var/backups it does)

If I jump ahead and try su discourse -c "bundle exec ruby script/import_scripts/bbpress.rb" anyway, I get the following result:

Loading existing users...
Loading existing categories...
Loading existing posts...
Loading existing topics...
Traceback (most recent call last):
        5: from script/import_scripts/bbpress.rb:512:in `<main>'
        4: from script/import_scripts/bbpress.rb:512:in `new'
        3: from script/import_scripts/bbpress.rb:21:in `initialize'
        2: from script/import_scripts/bbpress.rb:21:in `new'
        1: from /var/www/discourse/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `initialize'
/var/www/discourse/vendor/bundle/ruby/2.7.0/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect': Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) (Mysql2::Error::ConnectionError)

Thanks! I will take a look at the DB and the script and see if I can’t accomplish my purposes.

1 Like

Good luck! I wrote at least a couple importers before I “learned” Ruby. If you have an understanding of SQL that could be acquired in an undergraduate course in the mid 1980s, you can likely pull it off. If you write the queries something such that the field names in the resulting data match what the script expect you might be able to change only the SQL.

@pfaffman I’d really appreciate your help here, I’m very stuck

I’m pretty slammed right now and this likely isn’t solved here. Email with a budget and I’ll do my best to come up with a solution.

This seems like your MySQL server is either not running or is not installed properly.

1 Like


The post type should be post and needs to replace post_type topic. Tags were not brought over nor were the topics’ categories. All my posts were imported as an anonymous user, but it is certainly a decent start!

1 Like

Glad you’re making headway!

Thanks for this clear guide, it was key to my understanding of the import process instead of just blindly copy/pasting commands.

I’m still trying to figure out the fastest way to import a very large Drupal forum, and I still get the impression that things could be optimized in my case to shave off some downtime when I do the final production forum migration run. I may be a bit of a graybeard but I’m not yet totally sold on the whole Docker/containerization paradigm. I’m positive that I read somewhere that there was a Docker bug at some point that was causing massively slower performance of dockerized MySQL instances. On the Docker forum I’m seeing this report, but not sure if it’s still relevant. Also it might not be relevant in my case because I’m running Debian instead of Ubuntu on the host.

Another option might be to install MySQL or MariaDB on the host OS outside of the container?

And without getting into the weeds, what about optimizing the my.cnf with some suggestions from MySQLTuner ? The standard Docker configuration that works across the board for all instances can’t be optimal with its buffer pool instances and key buffer sizes, which make a massive difference on a dedicated production DB.