(phpBB3 Import) Cannot get phpbb3.rb script to connect to MySQL


(DrHogie) #1

(EDIT: deleted previous issues due to me having zero experience with docker and containers)’

I’ve gotten the phpbb3.rb script to work within the container and gotten all dependencies solved (including bbcode-to-md!) – however, I cannot get MySQL to connect properly.

The final command I’m running is:

RAILS_ENV=production bundle exec ruby script/import_scripts/phpbb3.rb bbcode-to-md

from within the Docker container. When I run this, the error message I get is:

loading existing groups...
loading existing users...
loading existing categories...
loading existing posts...
loading existing topics...
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/mysql2-0.3.16/lib/mysql2/client.rb:70:in `connect': Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) (Mysql2::Error)
	from /var/www/discourse/vendor/bundle/ruby/2.0.0/gems/mysql2-0.3.16/lib/mysql2/client.rb:70:in `initialize'
	from script/import_scripts/phpbb3.rb:26:in `new'
	from script/import_scripts/phpbb3.rb:26:in `initialize'
	from script/import_scripts/phpbb3.rb:391:in `new'
	from script/import_scripts/phpbb3.rb:391:in `<main>'

Now, the MySQL that I’ve installed the previous phpbb3 database to is NOT installed within the container, but on the server itself. Is there some hoodoo I need to perform to get the MySQL accessible from within docker?


Can't start PHPBB3 Importer
(Joe Seyfried) #2

@DrHogie, is this problem still there? I have just today fixed this for my extensive importer experiments by adding an ssh tunnel option to the launcher. Search line 487 in /var/discourse/launcher on your server (not in Docker that is):

exec ssh -o StrictHostKeyChecking=no root@${split[0]} -p ${split[1]}

…and replace it with:

exec ssh -R 3306:localhost:3306 -o StrictHostKeyChecking=no root@${split[0]} -p ${split[1]}

Now, ssh into Docker using ./launcher ssh app. You can now specify localhost as your mysql host in the importer script, but you also have to add a port to prevent it from connecting via a non-existing socket:

@client = Mysql2::Client.new(
  host: "localhost",
  port: "3306",
  username: "discourse",
  password: "s333cret",

(Rick Saenz) #3

I’m experiencing the same problem, except that I’m trying to do an import from Drupal.

I’ve loaded my Drupal DB into a MySQL instance running on my server outside of Docker, created users with the appropriate permissions, etc.

I’ve replaced line 487 in /var/discourse/launcher with this (pasted from my file):

exec ssh -R 3306:localhost:3306 -o StrictHostKeyChecking=no root@${split[0]} -p ${split[1]}

This is what happens outside Docker:

(master *) /var/discourse
$ irb
2.1.5 :001 > require 'mysql2'
 => true
2.1.5 :002 > @client = Mysql2::Client.new(
2.1.5 :003 >     host: "localhost",
2.1.5 :004 >     port: "3306",
2.1.5 :005 >     username: "discourse",
2.1.5 :006 >     password: "s333cret")
 => #<Mysql2::Client:0x0000000264d578 @read_timeout=nil, @query_options={:as=>:hash, :async=>false, :cast_booleans=>false, :symbolize_keys=>false, :database_timezone=>:local, :application_timezone=>nil, :cache_rows=>true, :connect_flags=>2147525125, :cast=>true, :default_file=>nil, :default_group=>nil, :host=>"localhost", :port=>"3306", :username=>"discourse", :password=>"#s333cret"}>

This is what happens inside Docker:

root@discourse-app:/var/www/discourse# irb
irb(main):001:0> require 'mysql2'
=> true
irb(main):002:0> @client = Mysql2::Client.new(
irb(main):003:1* host: "localhost",
irb(main):004:1* port: "3306",
irb(main):005:1* username: "discourse",
irb(main):006:1* password: "s333cret")
Mysql2::Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
    from /usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.3.17/lib/mysql2/client.rb:70:in `connect'
    from /usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.3.17/lib/mysql2/client.rb:70:in `initialize'
    from (irb):2:in `new'
    from (irb):2
    from /usr/local/bin/irb:12:in `<main>

(Joe Seyfried) #4

The key here is the

…therefore, I should probably put this in bold:

@client = Mysql2::Client.new(
host: “localhost”,
port: “3306”,
username: “discourse”,
password: “s333cret”,

If you omit the port, the database connection is attempted through a socket instead of a TCP connection. The socket does not work from inside Docker.


(Rick Saenz) #5

Joe,

In both examples given above I think the port is supplied. Did I do it wrong somehow? Thanks.

Rick


(Joe Seyfried) #6

Um - sorry. Didn’t see that. Try

host: "127.0.0.1"

instead of localhost.


(Rick Saenz) #7

Bingo! Thanks so much!


(Renis) #8

Trying to migrate from vBulletin, having the same problem with MySQL …

Can’t connect to local MySQL server

$ RAILS_ENV=production ruby vbulletin.rb
loading existing groups...
loading existing users...
loading existing categories...
loading existing posts...
loading existing topics...
/home/discourse/.gem/ruby/2.0.0/gems/mysql2-0.3.18/lib/mysql2/client.rb:70:in `connect': Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) (Mysql2::Error)
        from /home/discourse/.gem/ruby/2.0.0/gems/mysql2-0.3.18/lib/mysql2/client.rb:70:in `initialize'
        from vbulletin.rb:21:in `new'
        from vbulletin.rb:21:in `initialize'
        from vbulletin.rb:484:in `new'
        from vbulletin.rb:484:in `<main>'

how do I verify if the requirements for migration are installed…

thank you!

edit:

# gem install mysql2
Building native extensions.  This could take a while...
Successfully installed mysql2-0.3.18
1 gem installed