有没有办法在 AWS MySql/Aurora 上 运行 远程 shell 脚本引用 sql 远程文件

is there a way to run a remote shell script on AWS MySql/Aurora that references sql remote files

我正在尝试 运行 AWS MySQL 数据库上的初始化脚本,我已经能够 运行 MySQL 的本地实例上的相同脚本但在远程实例上尝试时不会。这是我 运行 的命令,来自包含 shell 脚本和 sql 资源文件的目录:

mysql -u user -p -h endpoint123.us-east-1.rds.amazonaws.com -P 3306 < create_database.sh

输入密码后出现以下错误:

ERROR 1064 (42000) at line 15: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near [line referencing SQL files]

基本上,脚本引用本地 sql 文件,这些文件也是安装完成所必需的。据我所知,无法将这些文件复制到 AWS RDS 机器上。有什么办法可以解决这个问题,让 shell 脚本可以 运行 正确吗?是通过复制文件还是通过 运行 远程 shell 脚本?提前致谢!

您似乎想将 shell 脚本的输出提供给 mysql。您使用的语法用于执行 mysql (sql) 脚本,而不是 shell 脚本的输出。你需要做这样的事情:

./script.sh | mysql -u abc -p -e

或者,分两个阶段:

./script.sh > out.sql  // To verify that the generated statements are correct
mysql -u abc -p -e < sql