主要问题出在数据库上,为了保证安装时不出问题使用了latin1,但使用过程中就出现中文乱码问题了,
有时在报错如:
java.sql.BatchUpdateException: Incorrect string value: '\xC9\xCF'
for column 'message' at row 1
或
Illegal mix of collations (latin1_bin,IMPLICIT) and
(utf8_general_ci,COERCIBLE) for operation '<='
为此,修改如下
vi /etc/my.cnf
[mysqld]
default-character-set=utf8
init_connect='SET NAMES utf8'
[client]
default-character-set=utf8
进入数据库mysql>,执行如下命令
ALTER DATABASE gitdb charset=utf8;
alter table account_diff_preferences
engine=innodb;
alter table account_external_ids engine=innodb;
alter table account_group_id engine=innodb;
alter table account_group_includes_by_uuid
engine=innodb;
alter table account_group_includes_by_uuid_audit
engine=innodb;
alter table account_group_members engine=innodb;
alter table account_group_members_audit
engine=innodb;
alter table account_group_names engine=innodb;
alter table account_groups engine=innodb;
alter table account_id engine=innodb;
alter table account_patch_reviews engine=innodb;
alter table account_project_watches engine=innodb;
alter table account_ssh_keys engine=innodb;
alter table accounts engine=innodb;
alter table change_id engine=innodb;
alter table change_message_id engine=innodb;
alter table change_messages engine=innodb;
alter table changes engine=innodb;
alter table patch_comments engine=innodb;
alter table patch_set_ancestors engine=innodb;
alter table patch_set_approvals engine=innodb;
alter table patch_sets engine=innodb;
alter table schema_version engine=innodb;
alter table starred_changes engine=innodb;
alter table submodule_subscriptions engine=innodb;
alter table system_config engine=innodb;
alter table tracking_ids engine=innodb;
ALTER TABLE account_diff_preferences CONVERT TO CHARACTER SET utf8
COLLATE utf8_general_ci;
ALTER TABLE account_external_ids CONVERT TO CHARACTER SET utf8
COLLATE utf8_general_ci;
ALTER TABLE account_group_id CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
ALTER TABLE account_group_includes_by_uuid CONVERT TO CHARACTER SET
utf8 COLLATE utf8_general_ci;
ALTER TABLE account_group_includes_by_uuid_audit CONVERT TO
CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE account_group_members CONVERT TO CHARACTER SET utf8
COLLATE utf8_general_ci;
ALTER TABLE account_group_members_audit CONVERT TO CHARACTER SET
utf8 COLLATE utf8_general_ci;
ALTER TABLE account_group_names CONVERT TO CHARACTER SET utf8
COLLATE utf8_general_ci;
ALTER TABLE account_groups CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
ALTER TABLE account_id CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
ALTER TABLE account_patch_reviews CONVERT TO CHARACTER SET utf8
COLLATE utf8_general_ci;
ALTER TABLE account_project_watches CONVERT TO CHARACTER SET utf8
COLLATE utf8_general_ci;
ALTER TABLE account_ssh_keys CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
ALTER TABLE accounts CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
ALTER TABLE change_id CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
ALTER TABLE change_message_id CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
ALTER TABLE change_messages CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
ALTER TABLE changes CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
ALTER TABLE patch_comments CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
ALTER TABLE patch_set_ancestors CONVERT TO CHARACTER SET utf8
COLLATE utf8_general_ci;
ALTER TABLE patch_set_approvals CONVERT TO CHARACTER SET utf8
COLLATE utf8_general_ci;
ALTER TABLE patch_sets CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
ALTER TABLE schema_version CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
ALTER TABLE starred_changes CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
ALTER TABLE submodule_subscriptions CONVERT TO CHARACTER SET utf8
COLLATE utf8_general_ci;
ALTER TABLE system_config CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
ALTER TABLE tracking_ids CONVERT TO CHARACTER SET utf8 COLLATE
utf8_general_ci;
目的就是保证都使用utf8编码,引擎使用innodb,目的就是为了保证索引长度大于1000时依然不出错。