Today, Clubot was upgraded, but after importing the data, Chinese characters are garbled, and one is to find the information to add the encoded information when the engine is created:
Engine = Create_engine ("Mysql://root: @localhost: 3306/clubot?charset=utf8")
But that's not OK, and then look at the table information:
> Show CREATE TABLE Clubot_members;clubot_members | CREATE TABLE ' clubot_members ' (' id ' int (one) not null auto_increment, ' email ' varchar () DEFAULT NULL, ' Nick ' varchar (50 Default NULL, ' Last_say ' timestamp null default NULL, ' Last_change ' timestamp null default NULL, ' Isonline ' int (one) DEFA ULT null, ' join_date ' timestamp null DEFAULT NULL, PRIMARY key (' id '), unique key ' email ' (' email '), unique key ' Nick ' (' N Ick ') Engine=innodb auto_increment=20 DEFAULT charset=latin1;
The latin1 encoding used to create the table was found, and the old table was created with Utf-8 encoding, and SQLAlchemy did not find a way to specify the specified encoding when the table was created. So only in MySQL itself to find:
> Show VARIABLES like "character%%" +--------------------------+-----------------------------+| variable_name | Value |+--------------------------+-----------------------------+| character_set_client | UTF8 | | character_set_connection | UTF8 | | Character_set_database | Latin1 | | Character_set_filesystem | binary | | Character_set_results | UTF8 | | Character_set_server | Latin1 | | Character_set_system | UTF8 | | Character_sets_dir | /data/share/mysql/charsets/|+--------------------------+-----------------------------+8 rows in Set (0.00 sec) > Show CREATE DATABASE clubot;+----------+-------------------------------------------------------------------+| Database | Create Database |+----------+-------------------------------------------------------------------+ | Clubot | CREATE DATABASE ' Clubot '/*!40100 DEFAULT CHARACTER SET latin1 */|+----------+-------------------------------------------------------------------+1 Row in Set (0.00 sec)
found that MySQL default and database are LATIN1 encoded, so change the database configuration
Copy the Code code as follows:
VI/ETC/MYSQL/MY.CNF # mysql config file on Ubuntu location, other systems may be different
Added under [client] [mysqld], respectively
Copy the Code code as follows:
Default-character-set = UTF8
At this time restart MySQL actually can't get up, say Default-character-set is invalid variable, view MySQL version found is 5.5, find data said 5.5 service-side encoding set variable is character-set-server, so will [Mysqld] Default-character-set = UTF8 change to Character-set-server = UTF8 and restart MySQL
Then change the database encoding:
Copy the Code code as follows:
ALTER DATABASE Clubot character set UTF8;
Delete the newly created table and re-import the data Chinese is fine.
Copy the Code code as follows:
> Use Clubot;
> drop table Clubot_status;
> drop table Clubot_infos;
> drop table clubot_history;
> drop table clubot_members;