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?

More than 1 year has passed since last update.

Ruby: MariaDB のバージョンを表示

Posted at

プログラム

フォルダー構造

$ tree -a
.
├── .env
├── config_mariadb.rb
└── server_version.rb
server_version.rb
#! /usr/bin/ruby
#
#	server_version.rb
#
#					Feb/24/2023
#
require 'mysql2'
#
load 'config_mariadb.rb'
# ------------------------------------------------------------
STDERR.puts "*** 開始 ***"
#
host,user,password,data_base = config_mariadb_proc()
client = Mysql2::Client.new(host: host, username: user, password: password, database: data_base)
#
sql_str="SELECT VERSION ()"
result=client.query(sql_str)
#
result.each do |row|
	print "#{row["VERSION ()"]}\n"
end
client.close
#
STDERR.puts "*** 終了 ***"
# ------------------------------------------------------------
config_mariadb.rb
#
#	config_mariadb.rb
#
#					Feb/24/2023
#
require 'dotenv'
#
# ------------------------------------------------------------
def config_mariadb_proc()
	Dotenv.load
	host = ENV['host']
	user = ENV['user']
	password = ENV['password']
	data_base = ENV['data_base']
#
	return	host,user,password,data_base
end
# ------------------------------------------------------------
.env
host = 'localhost'
user = 'scott'
password = 'tiger123'
data_base = 'city'

実行結果

$ ./server_version.rb 
*** 開始 ***
10.11.2-MariaDB
*** 終了 ***
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?