时间:2021-07-01 10:21:17 帮助过:23人阅读
导入一个数据库的时候查询的汉字编码为??? 于是 #mysql -uroot -p # mysql show variables like 'character_set_%'; ------------------------------------------------------ | Variable_name | Value | ----------------------------------------------
导入一个数据库的时候查询的汉字编码为???
于是
#mysql -uroot -p
#
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| 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 | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
ctrl+c 退出到终端
#whereis mysql
#find / -name 'my.cnf'
找到哦啊my.cnf在/etc/mysql/my.cnf
#vim /etc/mysql/my.cnf
在【client】下面加入
default-character-set=utf8
在【mysqld】下面加入
default-character-set=utf8
:wq
退出后
#/etc/init.d/mysql restart
提示
root@debian:/# /etc/init.d/mysql restart
Stopping MySQL database server: mysqld
.
Starting MySQL database server: mysqld.
Checking for corrupt, not cleanly closed and upgrade needing tables..
这个只是个提示,告诉你在做什么。不管它
再次进去mysql
#mysql -u root -p
#
输入
mysql> show variables like 'collation_%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
修改成功。再次查询数据。就好了
注意 如果修改后不能启动报错
试试把default-character-set=utf8改为character_set_server=utf8 改成后面这个,只需要mysqld下面的.client就不需要加了
5.5后的需要用改成这几个参数
[client] 下面加
default-character-set=utf8
[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci