mysql将表的字符编码转换成utf-8
复制代码代码如下:
1
|
alter table tb_anniversary convert to character
set
utf8;
|
修改数据库mysql字符编码为UTF8
步骤1:查看当前的字符编码方法
复制代码代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
mysql> show variables like
'character%'
;
+--------------------------+----------------------------+
|Variable_name |Value |
+--------------------------+----------------------------+
|character_set_client |latin1 |
| character_set_connection |latin1 |
| character_set_database |latin1 |
| character_set_filesystem |binary |
|character_set_results |latin1 |
|character_set_server |latin1 |
|character_set_system |utf8 |
|character_sets_dir |
/usr/share/mysql/charsets/
|
+--------------------------+----------------------------+
8 rows
in
set
(0.00 sec)
|
字符编码为latin1时,用户在给数据表插入一条字符类型(char)的记录,在显示此记录时可能会无法正常显示字符类型的数据,故此处我们将mysql字符编码修改为UTF8。操作如下:
步骤2:修改my.cnf配置文件,修改后如下(/etc/my.cnf):
复制代码代码如下:
1
2
3
4
5
|
[client]
#password = your_password
port = 3306
socket =
/var/lib/mysql/mysql
.sock
default-character-
set
=utf8
#设置默认编码为UTF8
|
下边是博主的配置
1
2
3
4
5
|
[client]
default-character-
set
=utf8
[mysqld]
#default-character-set=utf8
character-
set
-server = utf8
|
本文转自 蓝叶子Sheep 51CTO博客,原文链接:http://blog.51cto.com/dellinger/2043430,如需转载请自行联系原作者