Sha256: fc2b320543a291a457be166f17140c0a962c9053ebffdc05a9582350767e36fd

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

# encoding: utf-8

require 'mysql2'
require 'tempfile'

###### config start
host = "localhost" # req
database = "fluentd" # req
username = "root" # req
password = "yywx27" # req
tablename = "test" # req
columns = "txt,txt2" # option
data_file_path = "/Users/fukui_retu/myhome/dev/workspaces/fluent-plugin-mysql-load/exsamples/testdata.txt" # これは本来はいらない
fields_delimiter = "," # option.(default:",")いらない
fields_enclosed_optionally = true # option いらない
fields_enclosed = '"' # optionいらない
fields_escaped = '\\\\' # option いらない
lines_terminated = "\n" # option .(default:"¥n")いらない
lines_starting = ">" # option いらない
ignore_lines = 1 # optionいらない
###### config end

client ||= Mysql2::Client.new(:host => host, :username => username, :password => password, :database => database)
client.query("SELECT * FROM test").each do |r|
  puts r
end

# load data in fileを試す
query = "LOAD DATA INFILE \"#{data_file_path}\" INTO TABLE #{tablename}"
query += " FIELDS TERMINATED BY '#{fields_delimiter}' ENCLOSED BY '#{fields_enclosed}' ESCAPED BY '#{fields_escaped}'" 
query += " LINES TERMINATED BY '#{lines_terminated}' STARTING BY '#{lines_starting}'"
query += " IGNORE #{ignore_lines} LINES"
query += " (#{columns})"
print query

result = client.query(query);

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fluent-plugin-mysql-load-0.0.2 exsamples/connect_to_mysql.rb
fluent-plugin-mysql-load-0.0.1 exsamples/connect_to_mysql.rb