用中文原生表达方式重述:Ruby:显示MariaDB的版本号

程序

文件夹结构

$ tree -a
.
├── .env
├── config_mariadb.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
#
#					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
# ------------------------------------------------------------
host = 'localhost'
user = 'scott'
password = 'tiger123'
data_base = 'city'

执行结果

$ ./server_version.rb 
*** 開始 ***
10.11.2-MariaDB
*** 終了 ***
广告
将在 10 秒后关闭
bannerAds