MySQL once thought by the accident

  In October last year the entry of a new company, due to some internal discord caused by a PHP programmer in a hurry to leave, work related to the transfer of my hand.

  Speaking in front of the presence of internal discord factors, related project code is perfunctory quality, and also for the subsequent accident planted the bomb.

  By the end of the day, customers need to participate in a national project of an assessment, the bomb finally exploded.

  Open the project, all the ordinary users have encountered a normal visit, except the only official expert judging panel can not be accessed. All the experts more frightening only use the same account, and we know nothing of experts account.
  
  Customer bombed, anxious to die. Where overnight call the boss, the boss midnight phone to me. That night, according to the normal account, the normal business process gone again, did not find any problems. But experts do not know the account, it is impossible to know expert accounts, troubleshoot the problem can not naturally stay until the next day.

  The next morning, rushed to the client unit room, on-site access logging query.

  Strong pressure exerted against the customer, calm down, finally found an expert account to leave clues. So, follow it to find and put the root of the problem solved. Really thrilling, almost life was not guaranteed, to be sprayed dead client.

  Root of the problem is account expert assessment is "audit_expert" 12 bit length, the average user is a mobile phone number is 11 lengths. Look at the data sheet and found that the account fields account has been designed as varchar (11). Experts account is stored as "audit_exper", written when the database is truncated due to length limitations lost one.

  No wonder experts are killed not get logged. This sad reminder of the experts, data table design silly x. Then, adjust the length of the data type, manual restoration experts account. The problem is solved.
  
  MySQL once thought by the accident

  So the question is, how to avoid important data is truncated, resulting in dirty?

1. Modify the MySQL open STRICT_TRANS_TABLES sql_mode set strict mode.
MySQL once thought by the accident

2. The table storage engine is set to innoDB.

3. script when the data table write operations, take the initiative to catch the error and exception and early warning process.

Show

1. Write the table to test a-z a single data string of 26, MySQL throws an error message: ERROR 1406 (22001): Data too long for column 'name' at row 1. Failed to write data
MySQL once thought by the accident

2. Batch write data to the test table, test table storage engine is innodb. Error occurred finishing rollback.

MySQL once thought by the accident

Guess you like

Origin blog.51cto.com/phpme/2468028