Linux 如何从 bash 执行 .sql 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7616520/
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
How to execute a .sql script from bash
提问by user623879
Basically, I need to setup a database from a bash script. I have a script db.sql that does all this. Now how do I run this script from bash?
基本上,我需要从 bash 脚本设置数据库。我有一个脚本 db.sql 可以完成所有这些。现在我如何从 bash 运行这个脚本?
Database system is mysql
数据库系统是mysql
采纳答案by aioobe
You simply need to start mysql
and feed it with the content of db.sql
:
您只需要启动mysql
并提供以下内容即可db.sql
:
mysql -u user -p < db.sql
回答by Celso Dantas
If you want to run a script to a database:
如果要对数据库运行脚本:
mysql -u user -p data_base_name_here < db.sql