Method: Myreplicator::SqlCommands.mysql_export_outfile

Defined in:
lib/exporter/sql_commands.rb

.mysql_export_outfile(*args) ⇒ Object

Export using outfile \0 delimited terminated by newline Location of the output file needs to have 777 perms



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/exporter/sql_commands.rb', line 213

def self.mysql_export_outfile *args
  Kernel.p "===== mysql_export_outfile OPTIONS ====="
  
  options = args.extract_options!
  Kernel.p options
  options.reverse_merge! :flags => []
  db = options[:source_schema]

  # Database host when ssh'ed into the db server
  db_host = "127.0.0.1"
  Kernel.p "===== mysql_export_outfile ssh_configs ====="
  Kernel.p ssh_configs(db)
  if !ssh_configs(db)["ssh_db_host"].blank?
    db_host =  ssh_configs(db)["ssh_db_host"]
  elsif !db_configs(db)["host"].blank?
    db_host = db_configs(db)["host"]
  end
  
  flags = ""
  
  self.mysql_flags.each_pair do |flag, value|
    if options[:flags].include? flag
      flags += " --#{flag} "
    elsif value
      flags += " --#{flag} "
    end
  end
  
  cmd = Myreplicator.mysql
  cmd += "#{flags} "
  
  cmd += "-u#{db_configs(db)["username"]} -p#{db_configs(db)["password"]} "
  
  if db_configs(db).has_key? "socket"
    cmd += "--socket=#{db_configs(db)["socket"]} " 
  else
    cmd += "-h#{db_host} " if db_configs(db)["unuse_host_and_port"].blank?
    if db_configs(db)["unuse_host_and_port"].blank?
      cmd += db_configs(db)["port"].blank? ? "-P3306 " : "-P#{db_configs(db)["port"]} "
    end
  end
  
  cmd += "--execute=\"#{get_outfile_sql(options)}\" "
  Kernel.p cmd
  puts cmd
  return cmd
end