mysqlknife 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2ee2b0915fae46573419b2abd8bb4af707ddf9e
4
- data.tar.gz: 957ca26b80fd6f10c0a3460ccc554ae4d7064814
3
+ metadata.gz: 53677c0c444917af983ac901c03052cdb29ed3e6
4
+ data.tar.gz: b87aee8249871d370a69661c93dc8e02a120f5b3
5
5
  SHA512:
6
- metadata.gz: f0da2a9dd580946da50082e44d16e3014cfb5b43aa730819fe3c2fb616bb15443e52ffdc3242568b517fc893c932cfde592badb99458cc32a4759d5f5840ec41
7
- data.tar.gz: 3edb1981500349a11f9665cb819452071879065d1f51232937e7c3ee9e6129a3a65413b1800b4ecb09ad3f628c67bf38932fcaab40aa8f9f9d21ccf4334bc9d4
6
+ metadata.gz: 805c9aa77e5152d8971b3b6c9b214426917405463cd2fe77923e136ba46ae695b09e0eb0dc962e373294a5d980ee8be17e5bf196aacd51ab714e178e77d6bd4b
7
+ data.tar.gz: 126e56a02a2b9032016fdfd1ad8eaf0b009208a01d95a115a3e82ed707f8a3236740b60ca0787202824ab86da95591ab1b5116b3856512c555160defc6f306a2
data/README.md CHANGED
@@ -1,17 +1,34 @@
1
1
  # Mysqlknife
2
2
 
3
- TODO: Write a gem description
3
+ The missing utility for MySQL DBA:
4
+ - Checksum tables.
5
+ - Skip error is slave.
6
+ - Swap Databases
7
+ - Kill process for RDS or MySQL.
4
8
 
5
9
  ## Installation
6
10
 
7
11
  Install this tool executing the following command:
8
12
 
9
13
  ```Shell
10
- $ gem install mysqlkill
14
+ $ gem install mysqlknife
11
15
  ```
12
16
 
13
17
  ## Usage
14
18
 
19
+ ### Checksum table
20
+
21
+ Compare two tables with checksum:
22
+
23
+ ```Shell
24
+ $ mysqlknife checksum --from h=127.0.0.1,P=3306,u=root,p=admin,d=demo_from --to h=127.0.0.1,P=3306,u=root,p=admin,d=demo_to --table foo
25
+ ```
26
+
27
+ ### Skip error in slave.
28
+
29
+ ```Shell
30
+ $ mysqlknife skip --host 127.0.0.1 --user root --password admin --behind -120
31
+ ```
15
32
 
16
33
  ### Swap Databases
17
34
 
@@ -28,6 +45,9 @@ $ mysql -h 127.0.0.1 -u root -padmin < swap.sql
28
45
 
29
46
  ### Kill process
30
47
 
48
+ This action permit kill MySQL process in Amazon RDS or normal service, and log
49
+ output who kill.
50
+
31
51
  Please, follow next instructions to kill process:
32
52
 
33
53
  ```Shell
@@ -87,21 +87,45 @@ command :kill do |c|
87
87
  else
88
88
  kill = Mysqlknife::Kill.new(options.__hash__)
89
89
 
90
- if options.list.nil?
91
- kill.clear unless kill.list.first.nil?
92
- else
93
- unless kill.list.first.nil?
94
- table = Terminal::Table.new do |t|
95
- t.add_row(kill.list.first.keys)
96
- t.add_separator
90
+ if kill.check_privileges
91
+ if options.list.nil?
92
+ kill.clear unless kill.list.first.nil?
93
+ else
94
+ unless kill.list.first.nil?
95
+ table = Terminal::Table.new do |t|
96
+ t.add_row(kill.list.first.keys)
97
+ t.add_separator
97
98
 
98
- kill.list.each do |row|
99
- t.add_row(row.values)
99
+ kill.list.each do |row|
100
+ t.add_row(row.values)
101
+ end
100
102
  end
103
+ puts table
101
104
  end
102
- puts table
103
105
  end
106
+ else
107
+ puts 'User does not have process privileges.'
104
108
  end
105
109
  end
106
110
  end
107
111
  end
112
+
113
+ command :skip do |c|
114
+ c.description = 'Skipping the current replication error in Amazon RDS.'
115
+ c.syntax = %w(mysqlknife skip
116
+ --host 127.0.0.1
117
+ --user root
118
+ --password admin
119
+ --behind -120).join(' ')
120
+ c.option '--behind Integer', Integer, 'Set Seconds Behind Master, default is 120.'
121
+ c.action do |args, options|
122
+ if options.host.nil? ||
123
+ options.user.nil? ||
124
+ options.behind.nil?
125
+ puts c.syntax
126
+ else
127
+ rep = Mysqlknife::Replica.new(options.__hash__)
128
+ rep.skip
129
+ end
130
+ end
131
+ end
@@ -3,6 +3,7 @@
3
3
  require 'mysqlknife/config'
4
4
  require 'mysqlknife/connection'
5
5
  require 'mysqlknife/checksum'
6
+ require 'mysqlknife/replica'
6
7
  require 'mysqlknife/kill'
7
8
  require 'mysqlknife/sql'
8
9
  require 'mysqlknife/swap'
@@ -14,7 +14,6 @@ module Mysqlknife
14
14
  if @conn.execute(sql_user).first['CURRENT_USER'] =~ /^root\@/
15
15
  return true
16
16
  else
17
-
18
17
  return true if @conn.execute(sql_grants).first.values.to_s =~ /PROCESS/
19
18
  end
20
19
  end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ module Mysqlknife
4
+ class Replica
5
+ def initialize(options = {})
6
+ @conn = Connection.new(options)
7
+ @sql = Sql.new
8
+ @behind = options[:behind]
9
+ end
10
+
11
+ def check_status_negative(behind)
12
+ @behind < 0 && behind < 0 && behind <= @behind && behind != 0
13
+ end
14
+
15
+ def check_status_positive(behind)
16
+ @behind > 0 && behind > 0 && @behind <= behind && behind != 0
17
+ end
18
+
19
+ def skip
20
+ procedure_name = @sql.show_procedure('rds_skip_repl_error')
21
+ exist_procedure = @conn.execute(procedure_name)
22
+ slave_status = @conn.execute(@sql.slave_status).first
23
+
24
+ # Resolv Negative Lag:
25
+ if check_status_negative(slave_status['Seconds_Behind_Master'])
26
+ puts %W(#{Time.now.getutc} : MySQL Skip error replica -
27
+ #{slave_status.map { |k, v| "#{k}: #{v}" }.join(', ')}
28
+ ).join(' ')
29
+ if exist_procedure.first.nil?
30
+ @conn.execute(@sql.mysql_skip_repl_error)
31
+ while @conn.next_result
32
+ message = @conn.store_result
33
+ puts %W(#{Time.now.getutc} : MySQL Skip error replica -
34
+ Message: #{message}).join(' ')
35
+ end
36
+ else
37
+ message = @conn.execute(@sql.rds_skip_repl_error).first['Message']
38
+ puts %W(#{Time.now.getutc} : MySQL Skip error replica -
39
+ Message: #{message}).join(' ')
40
+ end
41
+ # Resolv Positive Lag:
42
+ elsif check_status_positive(slave_status['Seconds_Behind_Master'])
43
+ puts %W(#{Time.now.getutc} : MySQL Skip error replica -
44
+ Not implemented.).join(' ')
45
+ end
46
+ end
47
+ end
48
+ end
@@ -59,7 +59,7 @@ module Mysqlknife
59
59
  'event_scheduler')
60
60
  AND id != CONNECTION_ID()
61
61
  AND command != 'Binlog Dump').join(' ')
62
- sql << " AND #{where}" unless where.nil?
62
+ sql << " AND #{where};" unless where.nil?
63
63
  end
64
64
 
65
65
  def show_procedure(name)
@@ -96,5 +96,19 @@ module Mysqlknife
96
96
  end
97
97
  "SELECT SUM(CRC32(CONCAT(#{md5.join(', ')}))) AS sum FROM #{@table};"
98
98
  end
99
+
100
+ def slave_status
101
+ 'SHOW SLAVE STATUS;'
102
+ end
103
+
104
+ def rds_skip_repl_error
105
+ 'CALL mysql.rds_skip_repl_error;'
106
+ end
107
+
108
+ def mysql_skip_repl_error
109
+ %w(STOP SLAVE;
110
+ SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
111
+ START SLAVE;).join(' ')
112
+ end
99
113
  end
100
114
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Mysqlknife
4
- VERSION = '1.2.0'
4
+ VERSION = '1.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysqlknife
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicola Strappazzon C.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-05 00:00:00.000000000 Z
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.5.5
55
- description: MySQL knife tools
55
+ description: MySQL Knife tools
56
56
  email: nicola51980@gmail.com
57
57
  executables:
58
58
  - mysqlknife
@@ -64,6 +64,7 @@ files:
64
64
  - lib/mysqlknife/config.rb
65
65
  - lib/mysqlknife/connection.rb
66
66
  - lib/mysqlknife/kill.rb
67
+ - lib/mysqlknife/replica.rb
67
68
  - lib/mysqlknife/sql.rb
68
69
  - lib/mysqlknife/swap.rb
69
70
  - lib/mysqlknife/version.rb
@@ -93,5 +94,5 @@ rubyforge_project:
93
94
  rubygems_version: 2.1.11
94
95
  signing_key:
95
96
  specification_version: 4
96
- summary: ''
97
+ summary: The missing utility for MySQL.
97
98
  test_files: []