You must have heard that some developers, due to personal mistakes, did not add a where clause when deleting or updating statements, resulting in confusion in the entire table data. MySQL safe mode: MySQL will report an error when it finds that the delete or update statement does not have a where or limit condition. The entire SQL statement will not be executed, effectively preventing the accidental deletion of tables. Safe Mode SettingsCheck the status in mysql using the following command: show variables like 'sql_safe_updates'; The default state is OFF, just set the state to ON:
After setting to ON
testTest in safe mode 1. Update and delete without where clause delete from t_user > 1175 - You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column > Time: 0.001s
update t_user set name='123' > 1175 - You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column > Time: 0.001s 2. Delete of non-index keys delete from t_user where name='123' > 1175 - You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column > Time: 0.007s If the where condition of delete is not an index key, you must add a limit. delete from t_user where name='123' limit 1 > Affected rows: 0 > Time: 0.002s 3. Delete index key delete from t_user where group_id='123' > Affected rows: 0 > Time: 0s Summarize If
The
This is the end of this article about how to effectively prevent MySQL from deleting databases. For more information about preventing MySQL from deleting databases, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of the setting of background-image attribute in HTML
>>: Detailed explanation of tinyMCE usage and experience
This article shares the specific code of using ca...
Two parameters of Mysql paging select * from user...
The compatibility of browsers is getting better a...
Table of contents 1. Optional Chaining 2. Null va...
This article example shares the specific code of ...
Problem Description Recently, a host reported the...
Uninstall the system-provided MySQL 1. Check whet...
/******************** * Character device driver**...
In Linux, there are two types of file connections...
[Looking at all the migration files on the Intern...
Today, when I was on the road, a colleague sent m...
1. Basic knowledge (methods of date objects) 😜 ge...
When learning kubernetes, we need to practice in ...
Table of contents Preface Quick Review: JavaScrip...
Table of contents Overview (Loop Mode - Common) D...