CONVERT( )

Use this MySQL function to convert the character set of a given string to another character set specified with the USING keyword.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

CONVERT([_character_set]string USING character_set)

Explanation

Use this function to convert the character set of a given string to another character set specified with the USING keyword. This function is available as of version 4.0.2 of MySQL. The function has some similarities to CAST( ). If the character set for the given string is not the same as the default, you can specify its character set by listing it immediately before the string and preceded by an underscore.

Examples

UPDATE students SET name_first =
CONVERT(_latin1'Rosá' USING utf8)
WHERE student_id = 433342000;

In this example, we're updating the student's first name with the accented character into a format usable by the column that uses UTF8. Notice that the character set given for the string is preceeded by an underscore and there are no spaces before the quote mark for the string.