手动update或写入字段中文数据乱码解决壮阔东方æ½?奋进新æ—

比如我本地服务器端数据库更新或写入中文,在数据库查看正常,但是在vue前端则打印 壮阔东方æ½?å¥‹è¿›æ–°æ— ,这啥玩意儿~

定位到数据库编码问题

虽然在服务器端可以显示中文正常,在本地数据库服务端也显示正常,但是在客户端可能会显示乱码。因为我们的服务器是UTF8,这里就需要查看下数据库编码的问题了。如下操作

show variables like '%char%';

手动update或写入字段中文数据乱码解决壮阔东方æ½?奋进新æ—_第1张图片

> set character_set_server=utf8;
Query OK, 0 rows affected (0.01 sec)

> set character_set_database=utf8;
Query OK, 0 rows affected (0.00 sec)

> set character_set_client=utf8;
Query OK, 0 rows affected (0.00 sec)

> set character_set_connection=utf8;
Query OK, 0 rows affected (0.00 sec)

> set character_set_results=utf8;
Query OK, 0 rows affected (0.00 sec)

> show variables like '%char%';
+--------------------------+--------+
| 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   |
+--------------------------+--------+

手动update或写入字段中文数据乱码解决壮阔东方æ½?奋进新æ—_第2张图片

数据库中文显示 ????

> show variables like "char%";
+--------------------------+--------+
| Variable_name            | Value  |
+--------------------------+--------+
| character_set_client     | latin1 |
| character_set_connection | latin1 |
| character_set_database   | utf8   |
| character_set_filesystem | binary |
| character_set_results    | latin1 |
| character_set_server     | utf8   |
| character_set_system     | utf8   |
+--------------------------+--------+
7 rows in set (0.01 sec)

解决办法相同

> set character_set_server=utf8;
Query OK, 0 rows affected (0.01 sec)

> set character_set_database=utf8;
Query OK, 0 rows affected (0.00 sec)

> set character_set_client=utf8;
Query OK, 0 rows affected (0.00 sec)

> set character_set_connection=utf8;
Query OK, 0 rows affected (0.00 sec)

> set character_set_results=utf8;
Query OK, 0 rows affected (0.00 sec)

> show variables like '%char%';
+--------------------------+--------+
| 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   |
+--------------------------+--------+

你可能感兴趣的:(MySQL,web,mysql,vue)