MySQL コマンドの履歴と結果をファイルに記述する
![MySQL コマンドの履歴と結果をファイルに記述する](https://mebee.info/wp-content/uploads/2019/09/1_DZyivhX9QpnKxovKyQjZEw-890x500.png)
MySQLで、コマンドの履歴と結果をファイルに記述する手順を記述してます。
環境
- OS ubuntu21.10
- MySQL Ver 8.0.27-0ubuntu0.21.10.1 for Linux on x86_64 (Ubuntu)
手順
コマンドの履歴と結果をファイルに記述するには、「tee」を使用します。
tee ファイル名
実際に、使用してみます。
mysql> tee result.txt
実行後に以下のクエリを実行します。
mysql> select * from tbl1;
ERROR 1046 (3D000): No database selected
mysql> 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
mysql> select * from tbl1;
+----+--------+------+
| id | name | age |
+----+--------+------+
| 1 | taro | 10 |
| 2 | jiro | 20 |
| 3 | saburo | 50 |
| 4 | jiro | 20 |
| 5 | taro | 50 |
+----+--------+------+
5 rows in set (0.00 sec)
ファイルに記述されたかを確認してみます。
mysql> system cat result.txt
mysql> select * from tbl1;
ERROR 1046 (3D000): No database selected
mysql> 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
mysql> select * from tbl1;
+----+--------+------+
| id | name | age |
+----+--------+------+
| 1 | taro | 10 |
| 2 | jiro | 20 |
| 3 | saburo | 50 |
| 4 | jiro | 20 |
| 5 | taro | 50 |
+----+--------+------+
5 rows in set (0.00 sec)
コマンド上で行った全ての結果が表示されていることが確認できます。
終了する場合は、「notee」を実行します。
※noteeを実行したところまで記録されます。
mysql> notee
-
前の記事
MySQL 日付を指定して西暦0年から経過した日数を取得する 2022.03.29
-
次の記事
Vue.js ラジオボタンの値を取得する 2022.03.29
コメントを書く