Preface As you all know, we have encountered many cases in MySQL operation and maintenance where data was mistakenly updated or deleted due to incorrect update/delete conditions. To avoid similar problems, you can use the sql_safe_updates parameter to restrict update/delete. When this parameter is set to on, it can prevent the entire table from being updated or deleted due to program bugs or DBA manual errors. Without further ado, let’s take a look at the detailed introduction. There are a few things to note when setting this parameter: a. Before setting, you need to confirm that all updates and deletes in the program comply with the restrictions of sql_safe_updates, otherwise the program will report an error. b. 5.0 and 5.1 are both session-level, 5.6 is global&session-level; for lower-version databases, you can only Restriction Specifications: Example table structure: CREATE TABLE `delay_monitor` ( `id` int(11) NOT NULL, `Ftime` datetime DEFAULT NULL, `Fgtid` varchar(128) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin 1. Update a. Error conditions: without where, with where but no index, where condition is a constant Without where: With where and no index: Where the condition is a constant: b. Execution conditions: with where and index, without where + limit, with where and no index + limit, with where and index + limit, where condition is constant + limit With where and index: Without where + with limit: With where no index + limit: With where index + limit: Where the condition is constant + limit: 2. delete Compared with update, delete has stricter restrictions; if the where condition is a constant or empty, it will not be executed. a. Error conditions: without where, with where but no index, without where + with limit, where condition is a constant, where condition is a constant + limit Without where: With where and no index: Without where + with limit: Where the condition is a constant: where condition is constant + limit: b. Execution conditions: with where and index, with where without index + limit, with where with index + limit With where and index: With where no index + limit: With where index + limit: The summary is as follows: key means all, const means constant
Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM. You may also be interested in:
|
<<: Analyze the selection problem of storing time and date types in MySQL
>>: Detailed explanation of using top command to analyze Linux system performance
Preface When testing, in order to test the projec...
Solve the problem of Chinese garbled characters i...
——Notes from "MySQL in Simple Terms (Second ...
Preface Before leaving get off work, the author r...
1. Pull the image docker pull registry.cn-hangzho...
Connection query: It is the result of connecting ...
Download from official website: https://www.mysql...
When there are tens of thousands of records in th...
The first solution is to push the image to a publ...
Copy code The code is as follows: <iframe id=&...
This article example shares the specific code for...
1. Floating layout 1. Let the fixed width div flo...
Create a simple Spring boot web project Use the i...
About Recently, in the process of learning Vue, I...
Upgrade background: In order to solve the vulnera...