visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
294 experts, 1172 registered users, 1625 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


The DDRK link is back online.
We got a one week service interruption, sorry.
(23-30/01/2010)

Databases :: MySql :: problème avec accents dans mysqldump ; ANSI ? UTF-8 ? ISO-8859-1 ? problem !


By: Bernard France  Date: 29/03/2006 09:40:46  French English  Points: 20 Status: Answered
Quality : Excellent
Salut.

Quand je fais un "bête" mysqldump de ma base de données locale (serveur Windows) pour l'installer sur le serveur de production (unix), j'ai des problèmes.

Les versions du serveur MySqld sont pourtant compatibles (MySql 5.0.18-nt vers équivalent) et je croyais le résultat de mysqldump parfaitement compatible avec tout serveur, y compris au niveau de l'encodage des caractères accentués.

Or j'ai des erreurs concernant la SYNTAXE SQL (ce qui est un comble!) :

1) tous les accents sont pourris ; par exemple "é" devient "é". Les données importées via le dump sont donc corrompues.
All accentuated characters are mangled and for instance "é" becomes "é". I can not import that !

2) impossible d'importer le dump à cause de l'erreur :
executed 'DROP TABLE IF EXISTS `interface`;'
bad query 'CREATE TABLE `interface` (' : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

There seems to be an error in MySqld handling a mysqldump syntax !

Données d'exemple / sample data :

-- MySQL dump 10.10 -- -- Host: localhost Database: presskee -- ------------------------------------------------------ -- Server version 5.0.18-nt /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -- -- Table structure for table `interface` -- DROP TABLE IF EXISTS `interface`; CREATE TABLE `interface` ( `id` tinyint(3) unsigned NOT NULL, `symbole` char(2) NOT NULL, `actif` tinyint(3) unsigned default '0', UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `interface` -- /*!40000 ALTER TABLE `interface` DISABLE KEYS */; LOCK TABLES `interface` WRITE; INSERT INTO `interface` VALUES (1,'FR',1),(2,'EN',1); UNLOCK TABLES; /*!40000 ALTER TABLE `interface` ENABLE KEYS */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;



Je ne peux pas passer ce genre de dump à la console sur la machine cible, donc je l'exécute via un script PHP, ligne par ligne.
I can't pass this through the command-line interpreter on the target machine, thus I have to pass it line-by-line via a PHP script.

qu'arrive-t-il ?

Merci !
By: VGR Date: 29/03/2006 09:50:13 English  Type : Answer
Salut :D

C'est la ligne ci-dessous qui pose problème pour les accents ;
That's relatively simple. If you look at the headers that mysqldump produced, you'll notice the line /*!40101 SET NAMES utf8 */;. That's the one that "mangles" your Latin-1 characters.

Tu avais donc des caractères UTF-8 (beurk!) dans ton jeu de données, au lieu des Latin-1 (ISO 8859-1) attendus :D

L'erreur de syntaxe est due aux apostrophes introduites par défaut par mysqldump.
Also, the syntax error you get is because of the backquotes stupidly introduced by default by mysqldump around all litterals, including the ones that don't need them ! (no space therein, etc)

Tu pourras régler tous tes problèmes en relançant le dump :
You can solve your two problems by running mysqldump again with some arguments :
(substitute blue elements with real values)

mysqldump --user=root --password=*** --default-character-set=latin1 --skip-quote-names database_name > path_to_sql_dump_file


There is a page about mysqldump arguments & parameters on www.mysql.com but you can just run mysqldump --help and get the same (lengthy) result ;-)

best regards ;-)
By: Bernard Date: 08/04/2006 11:48:32 French  Type : Comment
correct 8-)

Do register to be able to answer

 Add This Article To:
 del.icio.usDel.icio.us  diggDigg  googleGoogle  spurlSpurl
 blinkBlink  wongWong  simpySimpy  yahooY! MyWeb 
EContact
browser fav
page generated in 63.876150 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page