J'ai le script python suivi (de tes.py):python encodage mysql :(
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import MySQLdb
query = "INSERT INTO test(test) VALUES ('ñ')"
print query + "\n"
conn = MySQLdb.connect (host = "localhost", user = "ibrick", passwd = "x", db = "ibrick", charset="utf8")
conn.names="utf8"
cursor = conn.cursor()
cursor.execute (query);
cursor.close()
conn.commit()
fichier encodage utf-8:
$ file -i tes.py
tes.py: text/x-java charset=utf-8
système de codage UTF:
#locale
LANG=es_AR.UTF-8
LC_CTYPE="es_AR.UTF-8"
LC_NUMERIC="es_AR.UTF-8"
LC_TIME="es_AR.UTF-8"
LC_COLLATE="es_AR.UTF-8"
LC_MONETARY="es_AR.UTF-8"
LC_MESSAGES="es_AR.UTF-8"
LC_PAPER="es_AR.UTF-8"
LC_NAME="es_AR.UTF-8"
LC_ADDRESS="es_AR.UTF-8"
LC_TELEPHONE="es_AR.UTF-8"
LC_MEASUREMENT="es_AR.UTF-8"
LC_IDENTIFICATION="es_AR.UTF-8"
LC_ALL=
echo "ñññ" > /tmp/test.txt
file /tmp/test.txt
/tmp/test.txt: UTF-8 Unicode text
Codage de table MYsql UTF8:
mysql> show create table test;
+-------+----------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+----------------------------------------------------------------------------------------------+
| test | CREATE TABLE `test` (
`test` varchar(10) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+----------------------------------------------------------------------------------------------+
Console outupt est OK:
#./tes.py
INSERT INTO test(test) VALUES ('ñ')
problème
:
Le script ne pas insérer ñ dans le tableau .. il insère un mauvais caractère:
select * from test;
+------+
| test |
+------+
| � |
| � |
| � |
| � |
| � |
| � |
| � |
+------+
7 rows in set (0.00 sec)
Tout le monde me aider? ?
Merci d'avance!
Avez-vous essayé SELECT avec python? Il pourrait être stocké correctement mais être foiré dans la sortie console de MySQL. –
Le sourire et le pied de page ne vous aident pas à obtenir des réponses, je les laisserais à l'avenir. – richo