class PXCBackup::MySQL
Attributes
datadir[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/pxcbackup/mysql.rb, line 9 def initialize(options = {}) @which = PathResolver.new(options) @username = options[:mysql_user] || 'root' @password = options[:mysql_pass] || '' @datadir = options[:mysql_datadir] || get_variable('datadir') || '/var/lib/mysql' raise 'Could not find mysql data dir' unless File.directory?(@datadir) end
Public Instance Methods
auth()
click to toggle source
# File lib/pxcbackup/mysql.rb, line 17 def auth "--user=#{@username.shellescape} --password=#{@password.shellescape}" end
exec(query)
click to toggle source
# File lib/pxcbackup/mysql.rb, line 21 def exec(query) output = Command.run("echo #{query.shellescape} | #{@which.mysql.shellescape} #{auth}", true) lines = output[:stdout].lines.to_a return nil if lines.empty? keys = lines.shift.chomp.split("\t") rows = [] lines.each do |line| values = line.chomp.split("\t") row = {} keys.each_with_index do |val, key| row[val] = values[key] end rows << row end rows end
get_status(variable)
click to toggle source
# File lib/pxcbackup/mysql.rb, line 48 def get_status(variable) result = exec("SHOW STATUS LIKE '#{variable}'") result ? result.first['Value'] : nil end
get_variable(variable, scope = 'GLOBAL')
click to toggle source
# File lib/pxcbackup/mysql.rb, line 39 def get_variable(variable, scope = 'GLOBAL') result = exec("SHOW #{scope} VARIABLES LIKE '#{variable}'") result ? result.first['Value'] : nil end
set_variable(variable, value, scope = 'GLOBAL')
click to toggle source
# File lib/pxcbackup/mysql.rb, line 44 def set_variable(variable, value, scope = 'GLOBAL') exec("SET #{scope} #{variable}=#{value}") end