在 Mac 命令行上,
$ sql -u foo -pbar db -B -e "SELECT * FROM t" > output.txt
需要输入内联命令。
如何在文件 foo.sql 中执行 SQL 语句,并且仍然以制表符分隔的形式将结果导出到另一个文件中?
编辑
当我做
mysql -h localhost -u foo -pbar db -B -e "SELECT * FROM t WHERE x='{}' LIMIT 2 INTO OUTFILE '../o.tsv';"
我有错误
ERROR 1045 (28000) at line 1: Access denied for user 'foo'@'localhost' (using password: YES)
但奇怪的是,
mysql -h localhost -u foo -pbar db
给我mysql命令提示符很好。使用是否OUTFILE
需要foo
具有特殊权限的用户?
mysql> SELECT * FROM user WHERE User='foo'\G
*************************** 1. row ***************************
Host: localhost
User: foo
Password: *A5DB2D927D6DF94DA5E1CE4B2AEAAB4D8304EA
Select_priv: N
Insert_priv: N
Update_priv: N
Delete_priv: N
Create_priv: N
Drop_priv: N
Reload_priv: N
Shutdown_priv: N
Process_priv: N
File_priv: N
Grant_priv: N
References_priv: N
Index_priv: N
Alter_priv: N
Show_db_priv: N
Super_priv: N
Create_tmp_table_priv: N
Lock_tables_priv: N
Execute_priv: N
Repl_slave_priv: N
Repl_client_priv: N
Create_view_priv: N
Show_view_priv: N
Create_routine_priv: N
Alter_routine_priv: N
Create_user_priv: N
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
1 row in set (0.01 sec)