官方介绍
is a Perl script that was originally written and contributed by Tim Bunce. It uses , , and cp or scp to make a database backup. It is a fast way to make a backup of the database or single tables, but it can be run only on the same machine where the database directories are located. works only for backing up MyISAM and ARCHIVE tables. It runs on Unix and NetWare.
To use , you must have read access to the files for the tables that you are backing up, the privilege for those tables, the privilege (to be able to execute ), and the privilege (to be able to lock the tables).
Mysqlhotcopy适用于小型数据库,适用 flush tables,locktables,cp(scp)备份数据库
shell#mysqlhotcopy -u 用户 备份数据库名称 目标文件夹
执行报错 :
install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (@INC contains: /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at (eval 12) line 3.
Perhaps the DBD::mysql perl module hasn't been fully installed,
or perhaps the capitalisation of 'mysql' isn't right.
Available drivers: DBM, ExampleP, File, Gofer, Proxy, SQLite, Sponge.
at /usr/local/mysql/bin/mysqlhotcopy line 178
原因 :缺少 perl连接数据库驱动
解决办法:
安装 perl-DBD-MySQL和 perl-DBI
关于 DBD和 DBI介绍
DBI is a database-independent interface for the Perl programming language. DBD::mysql is the driver for connecting to MySQL database servers with DBI.
· is the basic abstraction layer for working with databases in Perl.
· is the driver for using MySQL with DBI.
· is a pure-Perl implementation of the MySQL client-server protocol. (It is not necessary when using DBI with DBD::mysql, but may be useful in environments where you are not able to compile the MySQL client library required by DBD::mysql.)
接下来执行备份还是报错,
Invalid db.table name 'mysql.mysql`.`columns_priv' at /usr/local/mysql/bin/mysqlhotcopy line 854.
在网上查了下是 mysqlhotcopy脚本的 bug
解决办法
在 my @dbh_tables = eval { $dbh->tables() }; (应该是 834行 )这行下面添加
map { s/^.*?\.//o } @dbh_tables;
mysqlhotcopy常用参数
--addtodest 不重命名目标文件 (如果存在 ),合并它们【增量备份】
--allowold
--checkpoint 后面跟数据库名和表名 ,记录 mysqlhotcopy操作记录
--host
--port
--user
--tmpdir
--socket
--method 使用 cp或者 scp,默认使用 cp