1. database要utf8的
CREATE DATABASE spiderTest DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
2. 表要utf8的
use spiderTest
CREATE TABLE test
(
ID INT(18) PRIMARY KEY AUTO_INCREMENT,
test1 VARCHAR(500),
test2 VARCHAR(100),
test3 VARCHAR(100)
) ENGINE=INNODB CHARSET=utf8
3. Python链数据库也要utf8
import tracebackimport pymysql,pymssql
from DBUtils.PooledDB import PooledDB
# tmp = "insert into exch_no_rand_auto(stkcode) values(%s);" #SQL模板字符串
# l_tupple = [(i,) for i in range(100)] #生成数据参数,list里嵌套tuple
config = {
'host':'localhost'
,'user':'root'
,'password':'123456'
,'database':'spidertest'
,'charset':'utf8'
,'port':3306 #注意端口为int 而不是str
}
#调用函数
db = pymysql.connect(**config)
4. python文件最好也加上
# encoding=utf-8
声明utf8编码
5. MySQL执行以下查询,
SHOW VARIABLES LIKE 'character%';
瞅瞅谁还不是utf8
改一下character_set_server:
SET character_set_server='utf8';
还有修改MySQL的配置文件,我装的MySQL找了半天没找到配置文件在哪,又不想重装,先就这样弄吧
这下我是欧了,不知道你们欧不欧,不欧再搜搜吧,肯定还是编码的问题,不知道哪里漏了没设置好