Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no ipv6 support #279

Closed
naox opened this issue Jul 25, 2012 · 17 comments
Closed

no ipv6 support #279

naox opened this issue Jul 25, 2012 · 17 comments

Comments

@naox
Copy link

naox commented Jul 25, 2012

I've compiled mysql2 gem against newest mysql version

ldd mysql2.so

    libmysqlclient.so.18 => /usr/lib64/libmysqlclient.so.18 (0x00007fba0eeb8000)

and still there is no ipv6 support. I've compiled php against same mysql version and there are no problems.
My mysql server is at ipv6 adress. I connect to it by hostname that is translated by /etc/hosts

Gem mysql2 only gives error

Can't connect to MySQL server on 'mysql5' (111) (Mysql::Error)

cat /etc/hosts|grep mysql5

2a01:4f8:561:5165::c12 mysql5

Like I said there is zero problems with this configuration and php+mysql

@sodabrew
Copy link
Collaborator

Works fine for me. I created an ipv6-only user account, and can only connect to it when host => ::1.

Mysql2::Client.new 'host' => '::1', 'username' => 'ipv6user', 'password' => 'ipv6pass', 'database' => 'test_ipv6'

@sommero
Copy link

sommero commented Aug 8, 2013

same problem :( ... its 2013 and there're still problems with ipv6 ...

@simi
Copy link
Contributor

simi commented Aug 8, 2013

@sommero more details pls.

@sommero
Copy link

sommero commented Aug 8, 2013

@simi i had exactly the same problem as @naox ...

"Can't connect to MySQL server on 'r2d2'" (in my case)
the mysql server is only available via ipv6.

i found a workaround with socat:
/usr/bin/socat UNIX-LISTEN:/var/lib/mysql/mysql.sock,fork,mode=777,user=git TCP6:r2d2:3306 2> /dev/null &

@brianmario
Copy link
Owner

@sommero I too am able to connect to MySQL over ipv6 just fine. Could you provide us with all of the details about your environment so we can try to reproduce it ourselves?

@naox
Copy link
Author

naox commented Mar 11, 2015

Its 3 years later and I still can't connect to ipv6 mysql server. There are no problems (on same server) with php, no problems with python (connection libs compiled agains exacly same mysql lib) but gem mysql and mysql2 in ruby still don't support ipv6 connections to server.
All you get when using domain that has AAAA record only as mysql host is:
Unknown MySQL server host 'ipv6-mysql.naox.vipserv.org' (4) (Mysql2::Error)

@brianmario
Copy link
Owner

@naox interesting... We're just handing the host string passed in directly to libmysqlclient to do with it what it will. And as @sodabrew and I have both tested, ipv6 connectivity has definitely been verified and working. Maybe there are some other connection options being passed that are somehow conflicting? Is there also an A record for that domain that libmysqlclient is maybe attempting to use first? Have you tried passing the ipv6 address directly instead of a hostname?

@naox
Copy link
Author

naox commented Mar 11, 2015

Unknown MySQL server host '2a01:4f8:162:12e7::c1' (1) (Mysql2::Error)
  /home/naox/.gems/2.1/gems/mysql2-0.3.18/lib/mysql2/client.rb:70:in `connect'
  /home/naox/.gems/2.1/gems/mysql2-0.3.18/lib/mysql2/client.rb:70:in `initialize'
root@sv1 [/home/naox/.gems/2.1/gems/mysql2-0.3.18/lib/mysql2]# ldd mysql2.so
        linux-vdso.so.1 =>  (0x00007fff8f3d6000)
        libmysqlclient.so.18 => /var/mysql-5.5.29/lib/libmysqlclient.so.18 (0x00007f54f4592000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f54f4362000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f54f40df000)
        librt.so.1 => /lib64/librt.so.1 (0x00007f54f3ed6000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f54f3cd1000)
        libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f54f3a99000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f54f3740000)
        libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f54f343f000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f54f3231000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f54f4cfd000)

I have both php libs and python libs compiled against var/mysql-5.5.29/lib/libmysqlclient.so.18 and ipv6 works. Does ipv6 really work for you in mysql2 gem? If so I don't know what I can be doing wrong

Building native extensions.  This could take a while...
/usr/share/ruby-2.1.1/bin/ruby extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /usr/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Setting libpath to /var/mysql-5.5.29/lib
-----
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling client.c
compiling result.c
compiling mysql2_ext.c
compiling infile.c
linking shared-object mysql2/mysql2.so
make "DESTDIR=" install
/usr/bin/install -c -m 0755 mysql2.so ./.gem.20150311-20269-cwih6q/mysql2
installing default mysql2 libraries

Successfully installed mysql2-0.3.18

Only reasonable explanation whould be that gem is not likled to /var/mysql-5.5.29 (but to old mysql libs in system) even though it says it is

root@sv1 [/var/mysql-5.5.29/bin]# ./mysql -h '2a01:4f8:162:12e7::c1'
Welcome to the MySQL monitor.  Commands end with ; or \g.

@brianmario
Copy link
Owner

fwiw that ipv6 host is globally accessible:

irb(main):001:0> Mysql2::Client.new :host => "2a01:4f8:162:12e7::c1"
Mysql2::Error: Access denied for user 'brianmario'@'2601:9:7b80:68f:c4ac:9229:4955:ec1a' (using password: NO)
    from /Users/brianmario/<snip>/ruby/2.1.0/gems/mysql2-0.3.17/lib/mysql2/client.rb:70:in `connect'
    from /Users/brianmario/<snip>/ruby/2.1.0/gems/mysql2-0.3.17/lib/mysql2/client.rb:70:in `initialize'
    from (irb):1:in `new'
    from (irb):1
    from script/console:68:in `<main>'

Connecting appears to be working, but I got an auth error which I expected.

@brianmario
Copy link
Owner

And using the latest from master:

brianmario:mysql2.git brianmario$ bundle exec irb
irb(main):001:0> require 'mysql2'
=> true
irb(main):002:0> Mysql2::VERSION
=> "0.3.18"
irb(main):003:0> `git rev-list -1 HEAD`.rstrip
=> "5e21bf2f788d3eacac81f59c01d15f4c48e99bfc"
irb(main):004:0> Mysql2::Client.new :host => "2a01:4f8:162:12e7::c1"
Mysql2::Error: Access denied for user 'brianmario'@'2601:9:7b80:68f:c4ac:9229:4955:ec1a' (using password: NO)
    from /Users/brianmario/<snip>/mysql2.git/lib/mysql2/client.rb:70:in `connect'
    from /Users/brianmario/<snip>/mysql2.git/lib/mysql2/client.rb:70:in `initialize'
    from (irb):2:in `new'
    from (irb):2
    from /<snip>/rbenv/versions/2.1.5-github/bin/irb:11:in `<main>'

@naox
Copy link
Author

naox commented Mar 11, 2015

Thanks. To bad there seem to be no way to check compiled in mysql lib version - other then by ldd which I did it showed proper version.
In mysql, mysqli in php you can display such info using for example phpinfo(). Without such debuging options i'm stuck in my problems for probably next 3 years or more.
Only explanation that comes to mind seems to be that gem mysql2 is linked with wrong mysql lib version even though ldd shows right one.

example from php:

mysqli

MysqlI Support   enabled
Client API library version  5.5.29
Client API header version   5.5.29

@brianmario
Copy link
Owner

The Mysql2::Client#info instance method will give you the return values of mysql_get_client_version and mysql_get_client_info from the libmysqlclient C api. That should give you the correct version of the library that's been loaded. Is it different than what PHP is loading?

@naox
Copy link
Author

naox commented Mar 11, 2015

Unfortunetly I have no idea how to display this return value of "Mysql2::Client#info" because I don't program in ruby :( I'm only a guy that set ups mysql and ensures it always accessible

# irb
irb(main):001:0> require 'mysql2'
=> true
irb(main):002:0> Mysql2::Client#info
=> Mysql2::Client

@brianmario
Copy link
Owner

Oh sorry haha ;)

The hash character syntax in ruby is a documentation pattern for showing a method is an instance method. The hash character itself in Ruby syntax is the start of a comment, so in your example code above Ruby interpreted Mysql2::Client#info as just Mysql2::Client, which is a constant.

I'm not realizing that you have to have a successfully connected client in order to call this info method because we use the connection's encoding to transcode the string value we get back from the libmysqlclient C api into whatever the caller has defined with Encoding.default_internal, if it's set (it defaults to nil). But, I'm pretty sure the values we get back from that method will always be ASCII unless the caller is running some very custom version of libmysqlclient that has a version string with non-ascii characters in it...

Let me get a patch ready for that so you can get this info without needing to connect to a server first. I'll also add the libmysqlclient version that was linked against (what PHP is reporting as "header version" above). I'll cc you on the pull request once I have it open.

@naox
Copy link
Author

naox commented Mar 18, 2015

My problem was some old version in /home/naox/.gems/2.1/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.18/mysql2 which was not replaced after running "gem install mysql2". Deleting it solved this problem. However why was it there and why it was not replaced by "gem install mysql2" efectively blocking any updates to a gem?

some old mysql2.so compiled against old mysql lib but always used regardless of new "gem install mysql2":

naox@sv1 [/home/naox/.gems/2.1/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.18/mysql2]# ldd mysql2.so
ldd: warning: you do not have execution permission for `./mysql2.so'
        linux-vdso.so.1 =>  (0x00007fff05fff000)
        libmysqlclient_r.so.15 => /usr/lib64/libmysqlclient_r.so.15 (0x00007fe86f3b9000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fe86f19c000)
        libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fe86ef64000)
        libnsl.so.1 => /lib64/libnsl.so.1 (0x00007fe86ed4c000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fe86eac8000)
        librt.so.1 => /lib64/librt.so.1 (0x00007fe86e8bf000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007fe86e6bb000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fe86e361000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fe86f945000)

also i can confirm that #594 is now working for me after removing this old mysql2.so

@brianmario
Copy link
Owner

However why was it there and why it was not replaced by "gem install mysql2" efectively blocking any updates to a gem?

That's really strange. Maybe rubygems saw the existing version on disk, and since the gem you were trying to install had the same version number it just reused the cached copy? Nothing about the mysql2 gem build process should have been an issue there.

@naox
Copy link
Author

naox commented Mar 18, 2015

I've submited detailed issue on this to rubygems on github: rubygems/rubygems#1192

"gem install mysql2" does re-make file /home/user/.gems/2.1/gems/mysql2-0.3.18/ext/mysql2/mysql2.so while it does not (if file already exist)
/home/user/.gems/2.1/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.18/mysql2/mysql2.so and the second one is actualy used by "requre xxxx". This issue is not specific to mysql2 gem as I observed it on other gems. I had so much trouble debuging this issue because of that one of two .so files where linked correcly (ldd shown that) while I did not even known about other one which is for some reason actualy used by ruby.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants