SQLコマンドを実行していて、WARNINGが出た場合に警告を確認する方法。
①テストテーブル作成
CREATE TABLE `T1` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(10),
`comment` VARCHAR( 50 ),
PRIMARY KEY ( `id` )
) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
;
②検証用にデータをINSERTしてみる。
mysql> insert into T1(name,comment) values(‘SHOW WARINING’,’1111111′);
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> show warnings;
+———+——+——————————————-+
| Level | Code | Message |
+———+——+——————————————-+
| Warning | 1265 | Data truncated for column ‘name’ at row 1 |
+———+——+——————————————-+
1 row in set (0.00 sec)
mysql> select * from T1;
+—-+————+———+
| id | name | comment |
+—-+————+———+
| 1 | SHOW WARIN | 1111111 |
+—-+————+———+
1 row in set (0.00 sec)
③ –show-warningsオプション付きで接続してみる。
[root@colinux ~]# mysql -u root -p –show-warnings
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.30 MySQL Community Server (GPL)
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> use test
Database changed
mysql> insert into T1(name,comment) values(‘SHOW WARINING TEST’,’22222222222′);
Query OK, 1 row affected, 1 warning (0.01 sec)
Warning (Code 1265): Data truncated for column ‘name’ at row 1
mysql> select * from T1;
+—-+————+————-+
| id | name | comment |
+—-+————+————-+
| 1 | SHOW WARIN | 1111111 |
| 2 | SHOW WARIN | 22222222222 |
+—-+————+————-+
2 rows in set (0.00 sec)
mysql>