What are the disadvantages of default sql_mode in MySQL
This article mainly explains "what are the disadvantages of the default sql_mode in MySQL". The explanation in the article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the disadvantages of the default sql_mode in MySQL"?
The default mode is non-strict mode, and the inserted field is longer than the defined field will be automatically intercepted, and no error will be reported, resulting in data confusion.
Root@test 09:13:09 > select @ @ sql_mode
+-- +
| | @ @ sql_mode |
+-- +
| | NO_ENGINE_SUBSTITUTION |
+-- +
1 row in set (0.00 sec)
Root@test 09:41:54 > desc test
+-+ +
| | Field | Type | Null | Key | Default | Extra | |
+-+ +
| | id | int (11) | YES | | NULL |
| | name | varchar (10) | YES | | NULL |
+-+ +
2 rows in set (0.00 sec)
Root@test 09:46:28 > insert into test values (12, '11111111111111111111111111')
Query OK, 1 row affected, 1 warning (0.02 sec)
Root@test 09:47:19 > select * from test
+-+ +
| | id | name |
+-+ +
| | 1 | aa11 |
| | 2 | 1234 |
| | 3 | Ab |
| | 3 | ab |
| | 12 | 1111111111 | |
+-+ +
two。 So you need to set it to traditional mode, which means it's the traditional database mode, and it responds in the same way as oracle and sql server.
Root@test 09:46:53 > set sql_mode='traditional,NO_ENGINE_SUBSTITUTION'
Query OK, 0 rows affected (0.00 sec)
-- an error will be reported if the field is too long.
Root@test 09:47:15 > insert into test values (12, '11111111111111111111111111')
ERROR 1406 (22001): Data too long for column 'name' at row 1
Therefore, when our application changes from traditional database oracle to mysql, it is best to configure sql_mode='traditional,NO_ENGINE_SUBSTITUTION', so that there will not be some strange and strange behavior.
Thank you for your reading, the above is "what are the disadvantages of the default sql_mode in MySQL", after the study of this article, I believe you have a deeper understanding of the disadvantages of the default sql_mode in MySQL, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!