Ruby mysql2 error on migration

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.

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'
4 „Gefällt mir“

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:

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
4 „Gefällt mir“

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

3 „Gefällt mir“

Hi

I am facing this same situation but I am having trouble issuing these su discourse -c commands, they ask me for a password. I don’t think I created this user, it comes with the Docker container, so how do I get its password? Or how do I avoid being asked for one?

Thanks!

Is this a development install, an install from the standard guide, or something else?

If it’s from the standard guide you shouldn’t be prompted for a password when using su discourse -c from within the container.

1 „Gefällt mir“

Thanks, your confirmation that I “shouldn’t be prompted” sent me searching again, this time in a slightly different direction…

And I solved it! I was using a scripted command to enter the container that had slightly different options than the standard ./launcher enter app. One of them (maybe the absence of the --login option?) was causing this difference in behavior.

Anyway I am going to make sure I always use ./launcher going forward, there’s lots of stuff in there. Once again, thanks for your answer.

Another tip that might be useful for anyone else coming into this thread:

Using that command given above with IMPORT=1 will trigger this part of your Gemfile:

if ENV["IMPORT"] == "1"
  gem 'mysql2'
  gem 'redcarpet'
  gem 'sqlite3', '~> 1.3.13'
  gem 'ruby-bbcode-to-md', github: 'nlalonde/ruby-bbcode-to-md'
  gem 'reverse_markdown'
  gem 'tiny_tds'
end

I ran into problems with the installation of tiny_tds, and then with another thing it depends on called FreeTDS. After some wasted time on this I realized these are useful only for MS SQL imports, which I won’t be using, so I simply commented out the tiny_tds line in my Gemfile.

(it would be nice to have a comment in front of each of those packages saying what they are used for, if anyone knows)

2 „Gefällt mir“

Hallo. Ich habe hier dasselbe Problem, wenn ich dieses Skript ausführe, aber diese Befehle helfen nicht… Dies ist die Ausgabe, die ich erhalte, wenn ich versuche, Folgendes auszuführen: su discourse -c 'export IMPORT=1; bundle exec ruby script/import_scripts/vanilla_mysql.rb':

root@ip-xxx-xx-xx-xx-app:/var/www/discourse# su discourse -c 'export IMPORT=1; bundle exec ruby script/import_scripts/snuffhouse.rb'
Sie versuchen, im Bereitstellungsmodus zu installieren, nachdem Sie Ihre Gemfile geändert haben. Führen Sie `bundle install` woanders aus und fügen Sie die aktualisierte Gemfile.lock zur Versionskontrolle hinzu.

Wenn dies eine Entwicklungsumgebung ist, entfernen Sie den `/var/www/discourse/Gemfile` Freeze, indem Sie `bundle config unset deployment` ausführen.

Die Liste der Quellen hat sich geändert
Die Abhängigkeiten in Ihrer Gemfile haben sich geändert

Sie haben zur Gemfile hinzugefügt:
* mysql2
* redcarpet
* sqlite3 (~> 1.3, >= 1.3.13)
* ruby-bbcode-to-md
* reverse_markdown
* tiny_tds
* csv

Hallo, ich habe das Problem gelöst und vergessen, hier zu antworten. Die Sache ist, ich habe versucht, ein Migrationsskript für ein Forum auszuführen, das mysql verwendet, und stieß auf einige Fehler. Aber ich bin einfach den folgenden Schritten gefolgt und es hat gut funktioniert:

  • Innerhalb Ihrer Docker-Maschine, auf der Discourse läuft:
# In das Projektverzeichnis wechseln
cd /var/www/discourse

# MySQL-Abhängigkeiten installieren
apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y libmariadb-dev

# MySQL-Gems installieren (export = 1)
su discourse -c 'export IMPORT=1; bundle install'

# Skript ausführen (in diesem Fall vanilla_mysql)
su discourse -c 'export IMPORT=1; bundle exec ruby script/import_scripts/vanilla_mysql.rb'

Ich habe das gerade auf einer neuen Maschine gemacht, die ich hochfahren musste, und es hat genauso gut funktioniert.