0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rails コンソールで Amazon Aurora MySQL のバージョンを取得する

0
Last updated at Posted at 2025-11-20

やりたいこと

DB で Amazon Aurora MySQL を利用した Rails アプリケーションの Rails コンソール上で MySQL のバージョンを取得したい。

方法

まず aurora_version という関数を使って Aurora のバージョンを取得する。ちなみに ActiveRecord で直接 SQL を発行して単一の値を取得する場合は ActiveRecord::ConnectionAdapters::DatabaseStatements#select_value を使うと便利。

ActiveRecord::Base.connection.select_value('SELECT aurora_version();')
#=> "3.10.1"

次に以下のページを参照して Aurora のバージョンを MySQL のバージョンに読み替える。例えば Aurora の 3.10.1 に対応する MySQL のバージョンは 8.0.42

Database engine updates for Amazon Aurora MySQL version 3 - Amazon Aurora

Aurora MySQL database engine updates 2025-11-13 (version 3.11.0, compatible with MySQL 8.0.43)
Aurora MySQL database engine updates 2025-09-30 (version 3.10.1, compatible with MySQL 8.0.42)
Aurora MySQL database engine updates 2025-07-31 (version 3.10.0, compatible with MySQL 8.0.42)
Aurora MySQL database engine updates 2025-05-14 (version 3.09.0, compatible with MySQL 8.0.40)
(略)

ただし、毎回目視で確認するのは面倒なので Ruby でやる。Nokogiri を使うので、もし使っていない場合はインストールすること。

$ bundle install nokogiri
aurora_version = ActiveRecord::Base.connection.select_value('SELECT aurora_version();')
#=> "3.10.1"

# Rails コンソールではなく irb で実行する場合は以下を require すること。
# require 'nokogiri'
# require 'open-uri'

url = 'https://docs.aws.amazon.com/AmazonRDS/latest/AuroraMySQLReleaseNotes/AuroraMySQL.Updates.30Updates.html'
html = URI.open(url)
document = Nokogiri::HTML.parse(html)

version_regex = /version\s+(?<aurora_ver>\d+(?:\.\d+)+).+?(?<mysql_ver>\d+(?:\.\d+)+)/
comparison_table =
  document
    .css('li')
    .filter_map { |item| item.text.match(version_regex) }
    .to_h { |match_data| match_data.values_at(:aurora_ver, :mysql_ver) }
#=> 
# {"3.11.0"=>"8.0.43",
#  "3.10.1"=>"8.0.42",
#  "3.10.0"=>"8.0.42",
#  "3.09.0"=>"8.0.40",
#  "3.08.2"=>"8.0.39",
#  "3.08.1"=>"8.0.39",
#  "3.08.0"=>"8.0.39",
#  "3.07.1"=>"8.0.36",
#  "3.07.0"=>"8.0.36",
#  "3.06.0"=>"8.0.34",
#  "3.05.2"=>"8.0.32",
#  "3.05.1"=>"8.0.32",
#  "3.05.0.1"=>"8.0.32",
#  "3.05.0"=>"8.0.32",
#  "3.04.4"=>"8.0.28",
#  "3.04.3"=>"8.0.28",
#  "3.04.2"=>"8.0.28",
#  "3.04.1"=>"8.0.28"}

comparison_table[aurora_version]
#=> "8.0.42"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?