[MySQL/MariaDB] errorやwarningを確認する「show warnings」と即座に表示する方法

MySQL」、「MariaDB」でerrorやwarningを表示する「show warnings」を紹介します。

「show warnings」はmysqlコマンド固有のSQL文ですので、この機会にしっかりマスターしましょう。

DBはインストールされている前提ですので、

MariaDB・MySQLのインストール方法は下の記事を参考にしてください。

あわせて読みたい
LinuxへのMariaDBのインストールとデータベース作成 Linux上でMariaDBをインストールする手順とデータベース作成手順を紹介します。 MariaDBとは MySQLを元に作成されてオープンソースデータベース代表的なLinuxのディスト...
目次

show warnings:warningを表示する

warning、errorを表示するのは「show warnings;」を使用します。

show warnings;

以下実行例になります。

MariaDB [test001]> LOAD DATA LOCAL INFILE 'imp_test.txt' INTO TABLE test001 FIELDS TERMINATED BY '\t' ENCLOSED BY '"';
Query OK, 3930 rows affected, 1 warning (0.03 sec)
Records: 3930 Deleted: 0 Skipped: 0 Warnings: 1

MariaDB [test001]> show warnings;
+---------+------+------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+------------------------------------------------------------------------------+
| Warning | 1262 | Row 3930 was truncated; it contained more data than there were input columns |
+---------+------+------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [test001]>

  • 「Level」がwarningなのかerrorなのか種別を表示します。

  • 「Code 」は戻り値になります。

  • 「Message」はwarning , errorのメッセージを表示します。

–show-warnings:warningを即座に表示

「mysql」コマンドでDBへログイン時に

--show-warnings

句を使用することでwarningsを即座に表示することも出来ます。

mysql -u <DBユーザー> -p --show-warnings; 

以下実行例になります。

[root@test001 ~]# mysql -u root -p test001 -ppassword --show-warnings
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 52
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [test001]> LOAD DATA LOCAL INFILE 'imp_test001.txt' INTO TABLE test001 FIELDS TERMINATED BY '\t' ENCLOSED BY '"';
Query OK, 3930 rows affected, 1 warning (0.03 sec)
Records: 3930 Deleted: 0 Skipped: 0 Warnings: 1

Warning (Code 1262): Row 3930 was truncated; it contained more data than there were input columns

また「~/.my.cnf 」に設定を書いても同様に即座に表示することができます。

[mysql]
show-warnings

MariaDB & MySQL全機能バイブルposted with ヨメレバ

鈴木啓修/山田奈緒子 技術評論社 2015年01月

Amazon

Kindle

楽天ブックス

7net

honto

e-hon

紀伊國屋書店

よかったらシェアしてね!
  • URLをコピーしました!
目次