#! /usr/bin/ruby # # maria_read.rb # # Feb/23/2023 # # ------------------------------------------------------------------ require 'mysql2' # # ------------------------------------------------------------------ STDERR.puts "*** 開始 ***" # host = "localhost" user = "scott" password = "tiger123" data_base = 'city' client = Mysql2::Client.new(host: host, username: user, password: password, database: data_base) sql_str = "SELECT id,name,population,date_mod FROM cities order by ID" begin result = client.query(sql_str) result.each do |row| print "#{row['id']}\t#{row['name']}\t#{row['population']}\t#{row['date_mod']}\n" end end # client.close # STDERR.puts "*** 終了 ***" # ------------------------------------------------------------------