You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell中恢复MySQL数据库至Docker容器报错求助

解决Docker容器MySQL恢复时的PowerShell重定向错误

问题分析

你执行的命令逻辑错误,且PowerShell环境下输入重定向语法不兼容:

  • 恢复数据库是将本地sql文件导入容器MySQL,你误用了>(导出数据到文件),正确方向应为<(从文件读取输入)。
  • PowerShell原生不支持在docker exec命令中直接用<做输入重定向,会触发解析错误。

修正后的命令

方法1:用PowerShell管道传递文件内容

注意-u后必须指定用户名,-p后直接跟密码(无空格):

Get-Content db.sql | docker exec -i "containername" mysql -u你的用户名 -p你的密码 --force

方法2:通过cmd执行命令(绕过PowerShell解析限制)

cmd /c 'docker exec -i "containername" mysql -u你的用户名 -p你的密码 --force < db.sql'

错误日志翻译

The '<' operator is reserved for future use.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RedirectionNotSupported

翻译为:

'<' 运算符已保留供将来使用。
+ 类别信息 : 解析错误: (:) [], ParentContainsErrorRecordException
+ 完全限定错误ID : RedirectionNotSupported

内容的提问来源于stack exchange,提问作者Akshay Rathod

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 00:40:36