execute mysqlshell from within a bash script? is it possible?
3
votes
1
answer
1217
views
I am writing a backup script for a database and want to use mysqlshell
util.dumpSchemas()
utility.
But how on earth can I make it work from within a shell script?
The basic process I have is this:
filename_1: backup.sh
. . .
mysqlsh --file mysqlshell_backup.js
filename_2: mysqlshell_backup.js
\connect backup_user:@127.0.0.1:3306
util.dumpSchemas()
\q
But when I run it all I get are errors:
SyntaxError: Invalid or unexpected token at mysqlshell_backup.js:2:0
in \connect backup_user:@127.0.0.1:3306
but if I run the code manually, e.g:
mysqlsh
MySQL JS > \connect backup_user:@127.0.0.1:3306
it works fine.
MySQL 127.0.0.1:3306 ssl JS >
I tried making the file an executable in it's own right and running it on it's own by adding:
#!/usr/local/mysql-shell/bin/mysqlsh --file
\connect backup_user:@127.0.0.1:3306
util.dumpSchemas()
\q
but then I get:
mysqlshell_backup.js: line 2: connect: command not found
mysqlshell_backup.js: line 3: syntax error near unexpected token `[],'
mysqlshell_backup.js: line 3: `util.dumpSchemas()
But again, if I run it directly from within mysqlshell the code works fine, so I know there are no syntax errors.
Is there actually a way to run a mysqlshell command as part of a bigger script, or am I just wasting my time here?
Asked by IGGt
(2276 rep)
Jul 15, 2021, 03:34 PM
Last activity: Aug 26, 2021, 06:34 AM
Last activity: Aug 26, 2021, 06:34 AM