mysql delete duplicate data

Delete the duplicate data from a table. (Remaining one)

When the database is too big to execute SQL scripts, we would like to create indexes for tables.

So when it comes to the duplicate data, we can just delete duplicate ones by creating a unique index for the columns. Of course, this method is high-efficiency.

We can add indexes of the column that exists duplicate data

When the table is empty or now not exist duplicate data

We can create index using this command:

1
alter table table_name add unique index(column_name_1, column_name_2, ...);

This sentence can add union index

When the table is not empty and now exist duplicate data

1
alter ignore table table_name add unique index(column_name_1, column_name_2, ...);

The keyword ignore is important. It can remain only one line of duplicate data and this command is high-efficient.

Meanwhile, you have added an index for the column that you do not need to worry duplicate data next time.