我有後續的python腳本(tes.py):蟒蛇編碼的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()
文件編碼UTF-8:
$ file -i tes.py
tes.py: text/x-java charset=utf-8
系統編碼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
MYsql表編碼UTF8:
mysql> show create table test;
+-------+----------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+----------------------------------------------------------------------------------------------+
| test | CREATE TABLE `test` (
`test` varchar(10) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+----------------------------------------------------------------------------------------------+
控制檯outupt是OK:
#./tes.py
INSERT INTO test(test) VALUES ('ñ')
問題:
腳本不會插入表中的ñ..它插入一個人品不好:
select * from test;
+------+
| test |
+------+
| � |
| � |
| � |
| � |
| � |
| � |
| � |
+------+
7 rows in set (0.00 sec)
有人幫幫我嗎? ?
提前致謝!
您是否試過用python進行SELECT?它可能被正確存儲,但會在MySQL的控制檯輸出中混亂。 – 2012-02-06 02:32:03
笑臉和腳註不會幫助你獲得答案,我將在未來離開它們。 – richo 2012-02-06 04:12:20