The REPLACE statement first inserts the new row into the cities table with the information provided by the column list. The insertion fails because the row with id 2 already exists in the cities table therefore MySQL raises a duplicate-key error.
-----------------------------------------------------------------------
The REPLACE statement then updates the row that has the key specified in the value of the id column. In the normal process, it would delete the old row with conflict id first and then inserts a new row.