R
R
Relapse2016-04-02 15:47:11
MySQL
Relapse, 2016-04-02 15:47:11

Why are records randomly deleted from the MySQL database?

Hello.
The site has a MySQL database, type: MyISAM, database size: 25.7 GB, total rows: 133 million.
Records are spontaneously deleted from the database, and from different tables. Today I received a complaint from a user that his internal balance on my site was reset to zero. I checked it - it turned out that his account was deleted from users, while the data that relates to this user from other tables was preserved. Earlier there were cases when records from other bases were deleted. I won't say that the problem is massive, but even 20 out of 500,000 deleted records matter.
What could be the reason and how to get rid of the problem? Logging of deletion requests was done, there is nothing there.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2016-04-02
@melkij

MyISAM

Make me unsee it.
It's whatever the problem is. Store data and non-transactional storage are mutually exclusive. Use the only transactional storage in mysql - innodb. And add foreign keys.
It is somewhat unlikely that this is an immediate problem, in normal mode, even myisam should not selectively lose rows so that only a specific user notices it. More likely mysql's response is "ahhh, the table is corrupted, I'll only talk to the admin". However, I have not worked with myisam in production for a long time, maybe this behavior is also typical.
But FK in restrict mode will quite help from strange requests.

A
Alexey Nikolaev, 2015-02-21
@littleguga

This is a ternary comparison operator, its analogue can be if. What you wrote (in the context of a function) is similar

if($a > $b) {
    return 1;
} else {
    return -1;
}

In more detail, this expression means "if $a is greater than $b, return 1, otherwise return -1". What is after the sign "?", is executed when the condition is met, and what is after the ":" - in case of non-fulfillment thereof.
Nothing in this case is required to be learned or memorized, just remember that this is, in fact, just a different form of writing if ... else, only in the form of a ternary operator.
It is used because this form is more compact and often more beautiful than the standard if.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question