mysql将表的字符编码转换成utf-8
复制代码 代码如下:
alter table tb_anniversary convert to character set utf8;
修改数据库mysql字符编码为UTF8
步骤1:查看当前的字符编码方法
复制代码 代码如下:
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):
复制代码 代码如下:
[client]
#password = your_password
port = 3306
socket = /var/lib/mysql/mysql.sock
default-character-set=utf8 #设置默认编码为UTF8
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!