как сохранить запросы mysql автоматически, когда запрос выполняется с помощью терминала командной строки?

что я пробую, вот, я хочу сохранить запросы mysql и вывод этого запросы в файле и также показать на терминале человечности. Мой подход похож на это:

$ mysql -u user -pmysql |& tee day1.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
use AUDIT;
select * from CUSTOMERS;

Но это не показывает вывод, пока я не нажимаю ctrl +, D.It кажется им отправляющий мои запросы на mysql сервер. Я хочу видеть вывод запросов также в терминале, есть ли какой-либо способ сделать это?

0
задан 9 October 2018 в 03:32

1 ответ

Когда mysqlвывод не является терминалом, он принимает неинтерактивное использование и ожидает входа для окончания прежде, чем выполнить его. Можно использовать --tee опция (или связанное tee команда в mysql самостоятельно). От man mysql:

--tee=file_name

Append a copy of output to the given file. This option works only in interactive mode.
the section called “MYSQL COMMANDS”, discusses tee files further.

...

tee [file_name], \T [file_name]

By using the --tee option when you invoke mysql, you can log statements and their
output. All the data displayed on the screen is appended into a given file. This can
be very useful for debugging purposes also.  mysql flushes results to the file after
each statement, just before it prints its next prompt. Tee functionality works only in
interactive mode.

You can enable this feature interactively with the tee command. Without a parameter,
the previous file is used. The tee file can be disabled with the notee command.
Executing tee again re-enables logging.

Так:

mysql -u user -pmysql --tee=day1.sql
1
ответ дан 27 October 2019 в 08:40

Другие вопросы по тегам:

Похожие вопросы: