如何从bash执行.sql脚本

时间:2021-10-06 04:32:22

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数据库系统

2 个解决方案

#1


75  

You simply need to start mysql and feed it with the content of db.sql:

您只需启动mysql,并将其提供db.sql的内容:

mysql -u user -p < db.sql

#2


51  

If you want to run a script to a database:

如果您想运行一个脚本到数据库:

mysql -u user -p data_base_name_here < db.sql

#1


75  

You simply need to start mysql and feed it with the content of db.sql:

您只需启动mysql,并将其提供db.sql的内容:

mysql -u user -p < db.sql

#2


51  

If you want to run a script to a database:

如果您想运行一个脚本到数据库:

mysql -u user -p data_base_name_here < db.sql