Ruby mysql2 error on migration


(kodab) #1

Hi guys,

I’m trying to ue the vanilla_mysql.rb importer script to migrate my shitty forum to the awesome discourse platform. :slight_smile: However, when I execute the commands this happens:

root@discourse-app:/var/www/discourse# gem install mysql2 --platform=ruby
Building native extensions. This could take a while…
Successfully installed mysql2-0.4.6
1 gem installed

root@discourse-app:/var/www/discourse# bundle exec ruby script/import_scripts/vanilla_mysql.rb
script/import_scripts/vanilla_mysql.rb:1:in require': cannot load such file -- mysql2 (LoadError) from script/import_scripts/vanilla_mysql.rb:1:in'
root@discourse-app:/var/www/discourse#


What am I doing wrong / how can I fix it? :frowning: I’m using the default docker container on a clean ubuntu 16.04 vps.


(Gerhard Schlager) #2

Try this inside the docker container:

apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y libmysqlclient-dev
su discourse -c 'export IMPORT=1; bundle install --no-deployment --without test --without development --path vendor/bundle'
su discourse -c 'export IMPORT=1; bundle exec ruby script/import_scripts/vanilla_mysql.rb'

(kodab) #3

Thanks for your reply. Here is a short version of my output:

**root@discourse-app:/var/www/discourse#: su discourse -c 'export IMPORT=1; bundle install --no-deployment --without test --without development --path vendor/bundle'**
[[....]]
An error occurred while installing mysql2 (0.4.6), and Bundler cannot
continue.
Make sure that `gem install mysql2 -v '0.4.6'` succeeds before bundling.

**root@discourse-app:/var/www/discourse#: exec ruby script/import_scripts/vanilla_mysql.rb'**                               Could not find gem 'mysql2' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.

**root@discourse-app:/var/www/discourse#: bundle install**
[[....]]
Bundle complete! 96 Gemfile dependencies, 175 gems now installed.
Gems in the group development were not installed.
Bundled gems are installed into ./vendor/bundle.

**root@discourse-app:/var/www/discourse#: su discourse -c 'export IMPORT=1; bundle exec ruby script/import_scripts/vanilla_mysql.rb'**                               Could not find gem 'mysql2' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.

:confused:


(Gerhard Schlager) #4

You need to install a dependency for it to work. I guess it’s missing.

apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y libmysqlclient-dev

(kodab) #5

Thank you so mutch Gerhard! :slight_smile: It worked, I owe you.