1. REPLACE() String Function

The REPLACE() function is used to replace all occurrences of a substring within a string.

Syntax

REPLACE(str, from_str, to_str)

Example

SELECT REPLACE('Hello World', 'World', 'MySQL');
-- Result: 'Hello MySQL'

or

SELECT REPLACE('banana', 'a', 'o');
-- Result: 'bonono'

2. REPLACE Statement (Table Row Upsert)

MySQL also has a REPLACE INTO statement, which is similar to INSERT, but:

Syntax

REPLACE INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);