Ruby: 删除 MariaDB 的数据
程序
文件夹结构
$ tree -a
.
├── .env
├── config_mariadb.rb
└── maria_delete.rb
.env
config_mariadb.rb
可以在此找到
Ruby:显示MariaDB的版本
#! /usr/bin/ruby
#
# maria_delete.rb
#
# Feb/24/2023
#
require 'mysql2'
#
load 'config_mariadb.rb'
# ------------------------------------------------------------
def delete_proc (client,id)
sql_str="DELETE from cities where ID = '#{id}'"
client.query(sql_str)
end
# ------------------------------------------------------------
STDERR.puts "*** 開始 ***"
#
id_in = ARGV[0]
#
puts id_in
#
host,user,password,data_base = config_mariadb_proc()
client = Mysql2::Client.new(host: host, username: user, password: password, database: data_base)
#
delete_proc(client,id_in)
#
client.close
#
STDERR.puts "*** 終了 ***"
# ------------------------------------------------------------
执行结果
$ ./maria_delete.rb t3328
*** 開始 ***
t3328
*** 終了 ***