CREATE TABLE roles_users2 LIKE roles_users;
and for the future to prevent line duplication
ALTER TABLE roles_users ADD UNIQUE INDEX (role_id, user_id);
Or you can do it all in one step with ALTER TABLE IGNORE :
ALTER IGNORE TABLE roles_users ADD UNIQUE INDEX (role_id, user_id);
IGNORE is a MySQL extension for standard SQL. It controls how ALTER TABLE works if there are duplicates of unique keys in the new table or if warnings are turned on when strict mode is enabled. If IGNORE is not specified, the copy is aborted and rolled back if errors occur with duplicate keys. If IGNORE is specified, for rows with duplicates on a unique key, only the first row is used. The remaining conflicting lines are deleted. Invalid values ββare truncated to the nearest suitable value.
source share