如何将 sql 文件导入到 bash 脚本中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20050994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 08:40:19  来源:igfitidea点击:

How to import sql file into a bash script

mysqlsqllinuxbashdebian

提问by maxime

On Debian, I want to import a huge sql file with a command in a bash script. Currently, I use this command:

在 Debian 上,我想使用 bash 脚本中的命令导入一个巨大的 sql 文件。目前,我使用这个命令:

mysql -u root -p myDatabase < my_backup.sql

But that's not fine in a bash script because it asks for the root password ! I tried to provide it in the command with the -p argument, but it doesn't seems to work... Do someone have a solution ?

但这在 bash 脚本中不好,因为它要求输入 root 密码!我试图用 -p 参数在命令中提供它,但它似乎不起作用......有人有解决方案吗?

Thanks

谢谢

回答by Mark Setchell

There is no space between the "-p" and your password.

“-p”和您的密码之间没有空格。

Per mysql documentation:

根据 mysql 文档:

These work:

这些工作:

-uuser_name -ppassword 
-u user_name -ppassword 

This does not:

这不会:

-u user_name -p password 

http://forums.mysql.com/read.php?10,229253

http://forums.mysql.com/read.php?10,229253