Determine mysql2 server version using mysql2 Ruby gem
mysql2, ruby, ruby-on-rails
Solution
You can get the version info in rails via ActiveRecord::Base.connection. I'm doing it in my rails console here. I'm using an old version (2.2) of rails so the syntax might be different in yours.
irb(main):001:0> ActiveRecord::Base.connection.select_rows(
"SHOW VARIABLES LIKE '%version%'"
)
=> [
["innodb_version", "5.5.34"],
["protocol_version", "10"],
["slave_type_conversions", ""],
["version", "5.5.34-0ubuntu0.12.04.1"],
["version_comment", "(Ubuntu)"],
["version_compile_machine", "x86_64"],
["version_compile_os", "debian-linux-gnu"]
]
Once you've got this you can pull out the info you want, eg:
version = ActiveRecord::Base.connection
.select_rows("SHOW VARIABLES LIKE 'version'")
.last.last
=> "5.5.34-0ubuntu0.12.04.1"
Problem
I'm using `Rails` and the `mysql2` gem. Is there a way to get the mysqld server version as running the command: ``` $ mysqld --version mysqld Ver 5.5.29 for osx10.8 on i386 (Source distribution) ``` I do not wish to execute a shell command because the database server might be running on another server.