提问者:小点点

如何使用mysql.exe在windows命令行中执行多行sql语句?


在Linux shell上,我们可以在一行中执行sql命令,如multiline:

mysql -u username -usecret -e "show databases;use mydatabase;show tables;"
mysql -u username -usecret -e "show databases;
use mydatabase;
show tables;"

但是sql脚本中的multiline在Windows中似乎不起作用。

如何在Windows中执行多行sql语句?mysql多行是否有某种

# the following doesn't work in windows:
mysql.exe -u username -usecret -e "show databases;
use mydatabase;
show tables;"

当我使用echo并将其管道传输到mysql.exe时,输出的格式不是表

echo show databases; ^
use mydatabase; ^
show tables; | mysql.exe -u username -usecret

它只是输出

Database
information_schema
mydatabase
performance_schema
sys
...

我希望得到以下输出:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydatabase         |
| performance_schema |
| sys                |
+--------------------+
...

共1个答案

匿名用户

对于表格格式的输出,使用--table-t

echo show databases; ^
use mydatabase; ^
show tables; | mysql.exe -u username -usecret --table