percona-toolkit installation and use
percona-toolkit Profile
percona-toolkit is a set of high-level set of command-line tools used to perform various manually perform extremely complex and cumbersome system and mysql tasks, which include:
-
Consistency checks the master and slave data
-
Effectively archive records
-
Find Duplicate index
-
Summary information on the server
-
Analysis of queries from the logs and tcpdump
-
When the system is the problem of collecting important information system
percona-toolkit kit installation
#wget https://www.percona.com/downloads/percona-toolkit/2.2.20/deb/percona-toolkit_2.2.20-1.tar.gz
#tar zxf percona-toolkit_2.2.20-1.tar.gz
#cd percona-toolkit-2.2.20/
#perl Makefile.PL given as follows:
[root@b0d81312ea9e percona-toolkit-2.2.20]# perl Makefile.PL
Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 1.
BEGIN failed--compilation aborted at Makefile.PL line 1.
The error solution:
#yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker -y
Problem solving, Now I continue with the installation
#perl Makefile.PL
#make && make install
Successful installation!
---------------------------------------------------------------------------------------------------------
Now I use pt-online-schema-change percona -toolkit is to add a field to the table
pt-online-schema-change usefulness:
ALTER tables without locking them. During the modification will not cause obstruction to read and write, to add fields to the big table.
The principle:
If the table has a foreign key, unless -alter-foreign-keys-method to specify a particular value, otherwise the tool will not be executed.
1 Create a and you want to perform the same table structure alter table space operations.
2 performs a table structure changes, and the data of the original table to the copy to the table the table structure modifications,
3 created on the original table trigger the process of copy data, update operation of the original table is updated to the new table.
Note: the table has been defined trigger this tool will not work.
After 4 copy is complete, instead of the original table rename table with a new table, delete the original default table.
# pt-online-schema-change --alter "ADD COLUMN num INT" D=sls,t=lisa
// to lisa table in my mysql database to add a num sls field D: Specify the database t: Specifies the table
Given as follows:
Can't locate Time/HiRes.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/bin/pt-online-schema-change line 3727.
BEGIN failed--compilation aborted at /usr/local/bin/pt-online-schema-change line 3727.
The error means: the system does not have Perl installed components Time
The error solution:
# yum -y install perl-Time*
Add fields again to solve the problem:
# pt-online-schema-change --alter "ADD COLUMN num INT" D=sls,t=lisa
Again given as follows:
Operation, tries, wait:
analyze_table, 10, 1
copy_rows, 10, 0.25
create_triggers, 10, 1
drop_triggers, 10, 1
swap_tables, 10, 1
update_foreign_keys, 10, 1
Exiting without altering `sls`.`lisa` because neither --dry-run nor --execute was specified. Please read the tool's documentation carefully before using this tool.
Solution:
# pt-online-schema-change --alter "ADD COLUMN num INT" D=sls,t=lisa --user=sls --socket=/tmp/mysql.sock --password=122541 --execute
Given as follows:
You do not have the PROCESS privilege at /usr/local/bin/pt-online-schema-change line 4330.
Cause: The user is not authorized to sls
Solution
mysql>grant all privileges on *.* to sls@localhost identified by "122541";
mysql> flush privileges;
Add fields again to solve the problem:
# pt-online-schema-change --alter "ADD COLUMN num INT" D=sls,t=lisa --user=sls --socket=/tmp/mysql.sock --password=122541 --execute
Given as follows:
No slaves found. See --recursion-method if host b0d81312ea9e has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.
Operation, tries, wait:
analyze_table, 10, 1
copy_rows, 10, 0.25
create_triggers, 10, 1
drop_triggers, 10, 1
swap_tables, 10, 1
update_foreign_keys, 10, 1
Altering `sls`.`lisa`...
Creating new table...
Created new table sls._lisa_new OK.
Altering new table...
Altered `sls`.`_lisa_new` OK.
2016-12-24T08:54:54 Dropping new table...
2016-12-24T08:54:54 Dropped new table OK.
`sls`.`lisa` was not altered.
The new table `sls`.`_lisa_new` does not have a PRIMARY KEY or a unique index which is required for the DELETE trigger.
Cause: lisa does not create a primary key to the table
Solution:
mysql> alter table lisa add id int not null primary key auto_increment;
// id column must be lisa table nonexistent column. There is error.
Add fields again to solve the problem:
# pt-online-schema-change --alter "ADD COLUMN num INT" D=sls,t=lisa --user=sls --socket=/tmp/mysql.sock --password=122541 --execute
Success! ! !
No slaves found. See --recursion-method if host b0d81312ea9e has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.
Operation, tries, wait:
analyze_table, 10, 1
copy_rows, 10, 0.25
create_triggers, 10, 1
drop_triggers, 10, 1
swap_tables, 10, 1
update_foreign_keys, 10, 1
Altering `sls`.`lisa`...
Creating new table...
Created new table sls._lisa_new OK.
Altering new table...
Altered `sls`.`_lisa_new` OK.
2016-12-24T09:09:15 Creating triggers...
2016-12-24T09:09:15 Created triggers OK.
2016-12-24T09:09:15 Copying approximately 12 rows...
2016-12-24T09:09:15 Copied rows OK.
2016-12-24T09:09:15 Analyzing new table...
2016-12-24T09:09:15 Swapping tables...
2016-12-24T09:09:15 Swapped original and new tables OK.
2016-12-24T09:09:15 Dropping old table...
2016-12-24T09:09:15 Dropped old table `sls`.`_lisa_old` OK.
2016-12-24T09:09:15 Dropping triggers...
2016-12-24T09:09:15 Dropped triggers OK.
Successfully altered `sls`.`lisa`.
Success! ! !
Finally succeeded! ! I've been in love with myself! ! Ha ha ha