当我们安装完 gerrit 后,再页面的中文无法正常显示,需按照如下方法进行修改。
mysqldump -ugerrit2 -pgerrit2 reviewdb > /home/gerrit2/reviewdb.sql
cd /home/gerrit2/review_site/bin
./gerrit.sh stop
执行下面命令,查看 linux 系统是否已经安装中文字库宋体
fc-list :lang=zh-cn
如果没有安装,则按照下面步骤进行:
https://blog.csdn.net/u011606175/article/details/81006932
vi /etc/mysql/my.cnf
a) 在[client]下追加:
default-character-set=utf8
b) 在[mysqld_safe]下追加:
character-set-server = utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake
c) 在[mysqld]下追加:
character-set-server = utf8
a)可以使用phpmyadmin工具,对每个字段进行修改编码格式
略
b)也可以用mysql命令来对字段进行修改。
Show tables;
将数据库中所有的表导出来,然后按照如下格式填写,执行语句就可以了。
mysql –u root –p passw0rd
show databases;
use reviewdb;
alter table `account_diff_preferences` convert to character set utf8;
alter table `account_external_ids` convert to character set utf8;
alter table `account_group_by_id` convert to character set utf8;
alter table `account_group_by_id_aud` convert to character set utf8;
alter table `account_group_id` convert to character set utf8;
alter table `account_group_members` convert to character set utf8;
alter table `account_group_members_audit` convert to character set utf8;
alter table `account_group_names` convert to character set utf8;
alter table `account_groups` convert to character set utf8;
alter table `account_id` convert to character set utf8;
alter table `account_patch_reviews` convert to character set utf8;
alter table `account_project_watches` convert to character set utf8;
alter table `account_ssh_keys` convert to character set utf8;
alter table `accounts` convert to character set utf8;
alter table `change_id` convert to character set utf8;
alter table `change_message_id` convert to character set utf8;
alter table `change_messages` convert to character set utf8;
alter table `changes` convert to character set utf8;
alter table `patch_comments` convert to character set utf8;
alter table `patch_set_ancestors` convert to character set utf8;
alter table `patch_set_approvals` convert to character set utf8;
alter table `patch_sets` convert to character set utf8;
alter table `schema_version` convert to character set utf8;
alter table `starred_changes` convert to character set utf8;
alter table `submodule_subscriptions` convert to character set utf8;
alter table `system_config` convert to character set utf8;
在更改数据库表编码的时候遇到了下面几个错误:
a) mysql> alter table `account_external_ids` convert to character set utf8;
ERROR 1062 (23000): Duplicate entry 'gerrit:Ran.Huang' for key 'PRIMARY'
mysql> alter table `account_patch_reviews` convert to character set utf8;
ERROR 1062 (23000): Duplicate entry
'246-30925-1-vm_linux/third_party/source/loglevel/src/logLevel.cp' for key 'PRIMARY'
错误原因:表account_external_ids中的主键external_id里面的有内容有'gerrit:Ran.Huang'和'gerrit:ran.ruang',而set utf8默认的编码是uft8_general_ci,这是不区分大小写的,所以会报错
解决措施:alter table `account_external_ids` modify column `external_id` varchar(255) character SET utf8 COLLATE utf8_bin;
utf8_bin将字符串中的每一个字符用二进制数据存储,区分大小写。
b) mysql> alter table `account_project_watches` convert to character set utf8;
ERROR 1071 (42000): Specified key was too long; max key length is 1000 bytes
mysql> alter table `changes` convert to character set utf8;
ERROR 1071 (42000): Specified key was too long; max key length is 1000 bytes
mysql> alter table `submodule_subscriptions` convert to character set utf8;
ERROR 1071 (42000): Specified key was too long; max key length is 1000 bytes
错误原因:因为索引达到长度限制,所以报错。以utf8字符集为例,一个字符占3个bytes。因此在utf8字符集下,对myisam和innodb存储引擎创建索引的单列长度不能超过333个字符和255个字符
解决措施:
1)更改数据引擎为innodb,但是innodb读取数据速度慢【不采用】
修改vi /etc/mysql/my.ini,在[mysqld]下加上
default-storage-engine=INNODB
其中红色字体部分是要指定的引擎名称。
用sql语句修改已经建成表的引擎:
alter table table_name engine=innodb;
2)更改字段的字符长度
ALTER TABLE `accounts` CHANGE `full_name` `full_name` VARCHAR( 254 ) CHARACTER SET utf8 COLLATE utf8_general_ci
/etc/init.d/mysql restart
cd /home/gerrit2/review_site/bin
./gerrit.sh start