问题
I am trying to write a command-line script which will
- open Workbench
- connect to the specified database
- open an sql file
- run it
- export the results into a text file
I made use of workbench's guide for command-line guide from (https://dev.mysql.com/doc/workbench/en/wb-command-line-options.html) up to the point of opening the app and connecting to the database. However, I can't combine the options. The options I write after "connect to database" are not read or run properly.
My question is how to combine/pipe them together.
The following command runs the app and connects to the database:
"C:\..\MySQLWorkbench.exe" --query testdb
When I add --script C:\..\23.10.20.sql
or --open C:\..\23.10.20.sql
they have no effect. I only get the app connected to the database with an empty window.
I combine them like:
"C:\..\MySQLWorkbench.exe" --query testdb --script C:\..\23.10.20.sql
Is that the right way to combine them?
Edit: By trying two other options together, I confirmed that this is not the right way. I still need an answer for how to run 2 options one after the other.
The options from the workbench's guide I use are:
--query [connection|connection_string]:
Connection: Open a named connection.
--model modelfile: open the given EER model file.
--script script: Open the given SQL file in a connection, typically used with the --query parameter.
--run code: Execute the given code using the default language for GRT shell.
--open file: Open the given file at startup. Deprecated, so instead use specific types such as --script or --model.
Note: There is a note in this guide saying one dash (-) should be used for Windows instead of two (--). Although I am using Windows, that is not the case for me. The options are only run when I use two dashes. With one dash, nothing happens.
回答1:
You cannot use WB to export a result, only to open a specific connection and run a query or to run a python script. In principle it would be possible to use Python to export the data, but this is quite a lot of work for a small effect.
Instead I recommend not to use WB at all and instead work directly with MySQL in your script. A GUI is not well suited to do terminal work.
来源:https://stackoverflow.com/questions/64595764/how-do-i-run-2-options-of-mysql-workbench-together