MySQL中修正庫名的操作教程。本站提示廣大學習愛好者:(MySQL中修正庫名的操作教程)文章只能為提供參考,不一定能成為您想要的結果。以下是MySQL中修正庫名的操作教程正文
明天對clubot停止了進級, 然則導入數據後中文亂碼, 一開是找材料說是在創立引擎的時刻添加編碼信息:
engine = create_engine("mysql://root:@localhost:3306/clubot?charset=utf8")
然則這其實不行, 然後檢查表信息:
> show create table clubot_members; clubot_members | CREATE TABLE `clubot_members` ( `id` int(11) NOT NULL AUTO_INCREMENT, `email` varchar(100) DEFAULT NULL, `nick` varchar(50) DEFAULT NULL, `last_say` timestamp NULL DEFAULT NULL, `last_change` timestamp NULL DEFAULT NULL, `isonline` int(11) DEFAULT NULL, `join_date` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `email` (`email`), UNIQUE KEY `nick` (`nick`) ) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=latin1;
發明本來創立表的時刻用的latin1編碼, 而老的表是用utf-8編碼創立的, SQLAlchemy中並沒有發明有創立表時指定指定編碼的辦法. 所以只能在MySQL自己來找:
> 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)
發明 MySQL默許的和數據庫都是latin1的編碼, 所以更改數據庫設置裝備擺設
vi /etc/mysql/my.cnf # MySQL設置裝備擺設文件在Ubuntu上的地位, 其他體系能夠有差別
分離在[client] [mysqld]下添加
default-character-set = utf8
這時候重啟MySQL竟然起不來, 說default-character-set是有效的變量, 檢查MySQL版本發明是5.5, 找材料說5.5的辦事端編碼設置變量是character-set-server, 所以將[mysqld]上的default-character-set = utf8改成 character-set-server = utf8, 偏重啟MySQL
然後更改數據庫編碼:
alter database clubot character set utf8;
刪除新建的表, 偏重新導入數據中文就正常了
> use clubot;
> drop table clubot_status;
> drop table clubot_infos;
> drop table clubot_history;
> drop table clubot_members;