HAI LETTO L'ARTICOLO DI OGGI??? CLICCA QUI

Cultura informatica: wordpress pulire database

I lettori piu’ attenti, si saranno certamente accorti di un problema che affliggeva questo sito da un po’ di tempo: i caratteri accentati (“e’”, “o’” etc…) o speciali (virgolette a doppio apice “, e a singolo ‘) venivano sostituiti da caratteri illeggibili.

Questo a seguito di un attacco hacker che aveva cambiato il charset del sito.

Ho risolto in questa maniera:
Ho modificato il file “wp-config.php“; per intenderci, il file che tutti noi abbiamo modificato per installare WordPress con nome e password del database, quello che si trova solitamente nella directory di ogni installazione.

Ho inserito un “define(‘DB_COLLATE’, ‘utf8_general_ci’);” (senza virgolette a doppio apice) nel “wp-config.php

wordpress pulire database

Effettuato l’accesso su phpMyAdmin

Mi sono fatto generare tutte le istruzioni di modifica del charset delle tabelle con questa istruzione
(inserendo il nome del mio DB wordpress al posto di your_database_name):

SELECT CONCAT(“ALTER TABLE “,TABLE_SCHEMA,”.”,TABLE_NAME,” CHARACTER SET utf8 COLLATE utf8_general_ci; “,
“ALTER TABLE “,TABLE_SCHEMA,”.”,TABLE_NAME,” CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; “)
AS alter_sql
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = your_database_name;

Ho preso le stringhe generate e le ho lanciate.

E poi ho lanciato questi comandi per pulire wordpress dai caratteri strani rimasti:

— Contenuto post
update wp_posts
SET post_content = REPLACE (post_content, ‘è’, ‘e”)
where post_content LIKE ‘%è%’;

update wp_posts
SET post_content = REPLACE (post_content, ‘ò’, ‘o”)
where post_content LIKE ‘%ò%’;

update wp_posts
SET post_content = REPLACE (post_content, ‘ì’, ‘ì’)
where post_content LIKE ‘%ì%’ ;

update wp_posts
SET post_content = REPLACE (post_content, ‘ù’, ‘u”)
where post_content LIKE ‘%ù%’ ;

update wp_posts
SET post_content = REPLACE (post_content, ‘Ã’, ‘a”)
where post_content LIKE ‘%Ã%’;

update wp_posts
SET post_content = REPLACE (post_content, ‘a’³’, ‘o”)
where post_content LIKE ‘%a’³%’;

— Titoli post

update wp_posts
SET post_title = REPLACE (post_title, ‘è’, ‘e”)
where post_title LIKE ‘%è%’;

update wp_posts
SET post_title = REPLACE (post_title, ‘ò’, ‘o”)
where post_title LIKE ‘%ò%’;

update wp_posts
SET post_title = REPLACE (post_title, ‘ì’, ‘ì’)
where post_title LIKE ‘%ì%’ ;

update wp_posts
SET post_title = REPLACE (post_title, ‘ù’, ‘u”)
where post_title LIKE ‘%ù%’ ;

update wp_posts
SET post_title = REPLACE (post_title, ‘Ã’, ‘a”)
where post_title LIKE ‘%Ã%’;

— Link

update wp_links
SET link_name = REPLACE (link_name, ‘è’, ‘e”)
where link_name LIKE ‘%è%’;

update wp_links
SET link_name = REPLACE (link_name, ‘ò’, ‘o”)
where link_name LIKE ‘%ò%’;

update wp_links
SET link_name = REPLACE (link_name, ‘ì’, ‘ì’)
where link_name LIKE ‘%ì%’ ;

update wp_links
SET link_name = REPLACE (link_name, ‘ù’, ‘u”)
where link_name LIKE ‘%ù%’ ;

update wp_links
SET link_name = REPLACE (link_name, ‘Ã’, ‘a”)
where link_name LIKE ‘%Ã%’;

— Categorie
update wp_terms
SET name = REPLACE (name, ‘è’, ‘e”)
where name LIKE ‘%è%’;

update wp_terms
SET name = REPLACE (name, ‘ò’, ‘o”)
where name LIKE ‘%ò%’;

update wp_terms
SET name = REPLACE (name, ‘ì’, ‘ì’)
where name LIKE ‘%ì%’ ;

update wp_terms
SET name = REPLACE (name, ‘ù’, ‘u”)
where name LIKE ‘%ù%’ ;

update wp_terms
SET name = REPLACE (name, ‘Ã’, ‘a”)
where name LIKE ‘%Ã%’;

(Visited 42 times, 1 visits today)
4

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *