Dav*_*ins 4 command-line stdin
我试图找到一种方法来使用程序的输入文件,以便我也可以使用 stdin。
例如,假设我有一个创建表的 SQL 脚本。我这样调用它:
mysql -p database < script.sql
Run Code Online (Sandbox Code Playgroud)
这很好,但是当脚本完成时它会退出 mysql。相反,我想手动运行其他查询而无需退出 mysql。
我知道tee
可以将输出分叉到终端 (stdout) 和文件,是否有可用于输入的反向函数,或者至少可以应用于大多数 Linux/Unix 命令的方法?
我喜欢@Stephane 对一般情况的回答,但这里有一些更适合您的具体示例的内容。
启动 MySQL 交互模式,使用source
命令运行 SQL 脚本。
$ mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 947
Server version: 5.1.73-1 (Debian)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> source asdf.sql
+------+
| test |
+------+
| test |
+------+
1 row in set (0.00 sec)
mysql> select 'cool';
+------+
| cool |
+------+
| cool |
+------+
1 row in set (0.00 sec)
mysql>
Run Code Online (Sandbox Code Playgroud)