MySQL text string replacement

I recently switched to another platform for my personal site, and I had a problem when the previous character encoding, such as ", ""and ', is now transcoded strangely, like:

“
”
’
’
'

I have seen this before, and the last time I looked through manually and updated each article. However, this time I would like to take a more pragmatic approach by updating the database.

How could I replace all occurrences of these lines with my correct character?

I think it will look like:

SELECT REPLACE(''',''')

But do you have to be careful and include escape characters like \? Also, how do I perform this type of replacement across the entire database?

. phpMyAdmin , , "SQL". , , MySQL .

Update:

:

  • - "field_data_comment_body"
  • : "comment_body_value"
  • , , "longtext"

Johan, 0 :

DELIMITER $$

CREATE FUNCTION FixEncoding(input longtext) RETURNS longtext
BEGIN
  DECLARE output longtext;

  SET output = input;   
  SET output = REPLACE(output,''','\'');
  SET output = REPLACE(output,'’','\'');
  SET output = REPLACE(output,'” ','"');
  SET output = REPLACE(output,'“','"');
  SET output = REPLACE(output,'’','\'');

  RETURN output;
END $$

DELIMITER ;

UPDATE field_data_comment_body SET comment_body_value = FixEncoding(comment_body_value) WHERE entity_id <> 0;

: , 63 :

SELECT  `comment_body_value` 
FROM  `field_data_comment_body` 
WHERE  `comment_body_value` LIKE  '%&amp;#039;%'
LIMIT 0 , 30
+3
1

MySQL \.

, , - .

DELIMITER $$

CREATE FUNCTION FixEncoding(input varchar) RETURNS varchar
BEGIN
  DECLARE output varchar;

  SET output = input;   
  SET output = REPLACE(output,'&#039;','\'');
  SET output = REPLACE(output, .....
  .....

  RETURN output;
END $$

DELIMITER ;

UPDATE table1 SET column1 = FixEncoding(Column1) WHERE id <> 0;

, .

(), :

ALTER TABLE `test`.`test` CHARACTER SET latin1 COLLATE latin1_general_ci;
+3

All Articles