mysqlbinlog backup and mysqldump backup

-bash : mysqldump: command not found

-bash : mysqlbinlog:command not found

First you have to know the full path of the mysql command or mysqldump command, you can use the find command to find it

 

Find / -name mysql -print 
My mysql path is: /usr/local/mysql/bin/mysql, and then map a link to the /usr/bin directory, which is equivalent to creating a link file
ln -fs /usr/local /mysql/bin/mysql /usr/bin
Similarly: ln -s /usr/local/mysql/bin/mysqlbinlog /usr/bin

Before 5.7:
modify the my.cnf file and add log-bin=my-bin(my. The location of cnf is checked according to the path of your own installation)
# vi /usr/local/mysql/my.cnf
log-bin=my-bin #my-bin is the name of the bin-log file, you can customize the file name

or Customize the location where bin-log is stored. By default, it is in the mysql data directory, such as
log-bin=/mysql/data/my-bin
Note: The permissions of the /mysql/data folder require mysql.
The default is to have mysql-bin.00001 under /mysql/data/...
After modification, you need to restart mysql
# service mysql restart


View the mysql- bin.00001 log file :
mysqlbinlog mysql0bin.00001 |less For
example:
'/* !*/;
# at 120
#180412  8:53:44 server id 1  end_log_pos 203 CRC32 0xb1a0533f  Query   thread_id=5153988       exec_time=0
     error_code=0
SET TIMESTAMP=1523494424/*!*/;
SET @@session.pseudo_thread_id=5153988/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1075838976/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=45/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
# at 203
#180412 8:53:44 server id 1 end_log_pos 703 CRC32 0x04607463 Query thread_id=5153988 exec_time=0
     error_code=0
use `zabbix`/*!*/;
SET TIMESTAMP=1523494424/*!*/;
insert into history (itemid, clock, ns, value ) values (24103,1523494423,873193168,2.450000), (24283,1523494423,995677732,4.266667), (24163,1523494423,998621650,0.000000), (24523,1523494424,3255086,0.000000), (24164,1523494424,5611211,0.004164), (24104,1523494424,12912322,0.000000), (24344,1523494424,14527510,0.058611), (25064,1523494424,16363257,0.050000), (24284,1523494424,19002870,0.000000), (24524, 1523494424, 76535760, 95.865357)


You can use at to find the location, time, etc.
If you delete the database library or table, you can use mysql-bin.000012 to restore the document. View based on start/end time

with mysqlbinlog tool

mysqlbinlog --start-datetime='2016-08-02 00:00:00' --stop-datetime='2016-08-03 23:01:01' -d hadoop /data/mysql/data/mysql-bin.000001 is


based on the pos value, note: hadoop is the library name, /var/lib/mysql/mysql-bin.000001 is the binary file path
mysqlbinlog --start-position=2098 --stop -position=2205 -d hadoop /data/mysql/data/mysql-bin.000001

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325165057&siteId=291194637