The method of preventing the _mysql of Mysql database security

Source: Internet
Author: User

The MySQL database can use triggers to make it impossible to modify the data in some fields without affecting other fields being modified.

DROP TRIGGER IF EXISTS ' members ';
SET @OLD_SQL_MODE =@ @SQL_MODE, sql_mode= ';
DELIMITER//
CREATE TRIGGER ' members ' before UPDATE in ' members ' for each ROW BEGIN
 set New.name  = old.name;
   set new.cellphone = Old.cellphone;
 Set New.email  = Old.email;
  Set new.password = Old.password;
end//
DELIMITER;
SET sql_mode= @OLD_SQL_MODE;

Let me cite one more example:

CREATE TABLE ' account ' (
 ' id ' INT "UNSIGNED not NULL auto_increment,
 ' user ' VARCHAR" not null DEFAULT ' 0 '),
 ' cash ' FLOAT not NULL DEFAULT ' 0 ',
 PRIMARY KEY (' id ')
)
collate= ' utf8_general_ci '
engine=innodb;

Add a new piece of data to each data change

INSERT into ' test '. ' Account ' (' User ', ' cash ') VALUES (' Neo ', -10);
INSERT into ' test '. ' Account ' (' User ', ' cash ') VALUES (' Neo ',-5);
INSERT into ' test '. ' Account ' (' User ', ' cash ') VALUES (' Neo ');
INSERT into ' test '. ' Account ' (' User ', ' cash ') VALUES (' Neo ',-20);

Protect the user's balance from being modified

DROP TRIGGER IF EXISTS ' account ';
SET @OLD_SQL_MODE =@ @SQL_MODE, sql_mode= ';
DELIMITER//
CREATE TRIGGER ' account ' before UPDATE to ' account ' for each ROW BEGIN
 set New.cash  = old.cash;< c11/>end//
DELIMITER;
SET sql_mode= @OLD_SQL_MODE;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.