Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to turn off the strict mode of mysql

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "how to close the strict mode of mysql". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Close the mysql strict mode method: 1, open and edit the mysql configuration file "my.cnf"; 2, search for the "sql-mode" keyword, comment out the "sql-mode" related statements; 3, use the "service mysqld restart" command to restart mysql.

The operating environment of this tutorial: linux5.9.8 system, mysql8 version, Dell G3 computer.

Check to see if strict mode is enabled for Mysql:

Open the MySQL configuration file my.cnf (windows is my.ini).

Search sql-mode represents a non-strict pattern if it is not found.

When found, it means that strict mode is turned on, for example:

Sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

Turn on and off strict mode

Turn on strict mode:

Vi / etc/my.cnf # Edit the mysql configuration file to search for the sql-mode keyword. If not, add a line at the end of the file to replace it with: sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTIONservice mysqld restart restart mysql

Turn off strict mode:

Vi / etc/my.cnf # edits the mysql configuration file to search for the sql-mode keyword. Comment on sql-mode related statement # sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTIONservice mysqld restart restart mysql

Extended knowledge: comparison between strict model and non-strict model (loose model)

Inserting null values into not null fields is not supported

Inserting values for self-growing fields is not supported

Default values for text fields are not supported

Example:

CREATE TABLE `test_ table` (`id` int (11) NOT NULL AUTO_INCREMENT, `name` varchar (20) NOT NULL, `content` text NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8

1 not null field insert null value test

Insert a record with the value of name null

Execute in non-strict mode

Mysql > insert into test_table (content) values ('51ask'); Query OK, 1 row affected, 1 warning (0.00 sec) mysql > select * from test_table +-+ | id | name | content | +-+ | 1 | | 51ask | +-+ 1 row in set (0.00 sec) # executed successfully

Execute in strict mode

Mysql > insert into test_table (content) values ('51ask'); ERROR 1364 (HY000): Field' name' doesn't have a default value# failed to execute. Prompt field name cannot be null

The above three points will no longer be tested.

Thus it can be seen that the use of mysql strict mode can make the data more secure and strict, but the disadvantage is to reduce the compatibility of empty data into the database. It is recommended that the development environment use strict patterns to improve the quality of code and the rigor of data.

This is the end of "how to turn off the strict Mode of mysql". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report