使用AutoMySQLBackup 3.0做逻辑备份时,测试验证时发现AutoMySQLBackup使用mysqldump导出的数据库备份有问题,如下测试所示:
$ ls
daily fullschema latest monthly status tmp weekly
$ cd daily/
$ ls
kkkk mysql performance_schema sys
$ cd kkkk/
$ ls
daily_kkkk_2021-09-22_16h45m_Wednesday.sql.gz
$ gunzip daily_kkkk_2021-09-22_16h45m_Wednesday.sql.gz
$ more daily_kkkk_2021-09-22_16h45m_Wednesday.sql
-- MySQL dump 10.13 Distrib 5.7.34, for Linux (x86_64)
--
-- Host: 127.0.0.1 Database: kkkk
-- ------------------------------------------------------
-- Server version 5.7.34-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2021-09-22 16:45:39
如上所示,测试发现没有导出对应数据库中的任何数据,经过测试和验证,最终发现是因为AutoMySQLBackup使用的数据库账号mybackup(参数CONFIG_mysql_dump_username指定的账号)的权限有问题。如下所示,此账号是Xtrabackup备份使用的一个账号,所以也用来做AutoMySQLBackup的账号使用,但是忘记设置相关权限了
mysql> show grants for mybackup@'127.0.0.1';
+------------------------------------------------------------------------------------------------------------------+
| Grants for mybackup@127.0.0.1 |
+------------------------------------------------------------------------------------------------------------------+
| GRANT RELOAD, PROCESS, SUPER, LOCK TABLES, REPLICATION CLIENT, CREATE TABLESPACE ON *.* TO 'mybackup'@'127.0.0.1'|
| GRANT SELECT, INSERT ON `performance_schema`.* TO 'mybackup'@'127.0.0.1' |
+------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysqldump是需要一些特定权限的,如下所示。
GRANT SELECT, RELOAD, LOCK TABLES, REPLICATION CLIENT, SHOW VIEW, EVENT, TRIGGER ON *.* TO 'mybackup'@'127.0.0.1';
FLUSH PRIVILEGES;
重新授予相关权限,重新测试验证,发现已经正常,如下所示。但是这种情况下,AutoMySQLBackup居然没有任何错误提示,而且也生成了对应的sql压缩文件。所以在使用过程中,千万要小心,一定要注意设置权限,测试验证备份文件是否正常。
$ more daily_kkkk_2021-09-22_16h47m_Wednesday.sql
-- MySQL dump 10.13 Distrib 5.7.34, for Linux (x86_64)
--
-- Host: 127.0.0.1 Database: kkkk
-- ------------------------------------------------------
-- Server version 5.7.34-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `test`
--
DROP TABLE IF EXISTS `test`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `test` (
`id` int(11) DEFAULT NULL,
`name` varchar(12) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `test`
--
LOCK TABLES `test` WRITE;
/*!40000 ALTER TABLE `test` DISABLE KEYS */;
INSERT INTO `test` VALUES (1,'kery'),(2,'kkk');
/*!40000 ALTER TABLE `test` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2021-09-22 16:47:22