mysqldump: Got error: 1356 mysqldump的重要参数--force
一个MySQL的备份突然变小了很多,但实际的数据量却一直在增长。备份脚本也没有调整过。为什么呢?
重现了一下备份过程,发现备份中遇到了如下错误:
mysqldump: Got error: 1356: View 'wordpress.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them when using LOCK TABLES
原因: 视图引用的表不存在。
原理:mysqldump在备份时要对表加读锁,加锁失败的时候。备份就终止了。
解决方法:在备份时加上--force参数
模拟测试如下:
正常情况:
1.创建表t1并插入数据
CREATE TABLE `t1` (
`a` int(11) NOT NULL,
`b` int(11) DEFAULT NULL,
`c` int(11) DEFAULT NULL,
PRIMARY KEY (`a`),
UNIQUE KEY `b` (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into t1 values(1,3,5);
2.基于表t1创建视图
create view v_t1 as select * from t1;
3.模拟备份,可以正常备份出数据
mysqldump -ubkpuser -ps3cret wordpress>wordpress.sql
模拟视图引用的表被删除:
1.删除表t1
mysql> drop table t1;
Query OK, 0 rows affected
mysql> select * from v_t1;
1356 - View 'wordpress.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
2. 模拟备份,失败
$mysqldump -ubkpuser -ps3cret wordpress >wordpress1.sql
Warning: Using a password on the command line interface can be insecure.
mysqldump: Got error: 1356: View 'wordpress.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them when using LOCK TABLES
3. 增加force参数后,虽然有错误,但不影响备份
$mysqldump -ubkpuser -ps3cret --force wordpress >wordpress1.sql
Warning: Using a password on the command line interface can be insecure.
mysqldump: Got error: 1356: View 'wordpress.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them when using LOCK TABLES
mysqldump: Couldn't execute 'SHOW FIELDS FROM `v_t1`': View 'wordpress.v_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them (1356)
[clouder@server2-86 ~]$ /home/clouder/vs/program/mysql/bin/mysqldump -uroot -p11 -S /home/clouder/vs/program/mysql/run/mysql.sock -h 172.16.2.86 --all-databases --master-data=1 --flush-logs --force > /home/clouder/backup/alldatabase`date +%F-%H-%M-%S`.sql
mysqldump: Couldn't execute 'SHOW FIELDS FROM `ApiCommandAliasView`': View 'api.ApiCommandAliasView' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them (1356)
mysqldump: Couldn't execute 'SHOW FIELDS FROM `ApiReset`': View 'api.ApiReset' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them (1356)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App