MariaDB コマンドの実行履歴と結果をファイルに記録する

MariaDB コマンドの実行履歴と結果をファイルに記録する

MariaDBで、コマンドの実行履歴と結果をファイルに記録する手順を記述してます。「tee」で記録するファイルを指定して「notee」で記録を終了することができます。実際に実行した結果も記述してます。

環境

  • OS CentOS Stream release 9
  • MariaDB 10.10.2
  • phpMyAdmin 5.2.0

手順

コマンドの実行履歴と結果をファイルに記録するには、「tee」を使用します。

tee ファイル名

実際に、「result.txt」というファイルに記録してみます。

MariaDB [(none)]> tee result.txt

Logging to file 'result.txt'

実行後に以下のクエリを実行します。

MariaDB [(none)]> use foo;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [foo]> select * from tbl1;
+----+--------+------+
| id | name   | age  |
+----+--------+------+
|  1 | itiro  |   10 |
|  2 | jiro   |   20 |
|  3 | sabpro |   30 |
|  4 | siro   |   40 |
|  5 | goro   |   50 |
+----+--------+------+
5 rows in set (0.001 sec)

ファイルに記録されたかを確認してみます。

MariaDB [(none)]> system cat result.txt

MariaDB [(none)]> use foo;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [foo]> select * from tbl1;
+----+--------+------+
| id | name   | age  |
+----+--------+------+
|  1 | itiro  |   10 |
|  2 | jiro   |   20 |
|  3 | sabpro |   30 |
|  4 | siro   |   40 |
|  5 | goro   |   50 |
+----+--------+------+
5 rows in set (0.001 sec)

コマンド上で行った、全ての結果がファイルに記録されていることが確認できます。

終了する場合は、「notee」を実行します。
※noteeを実行したところまで記録されます。

MariaDB [foo]> notee
Outfile disabled.