mysql将表的字符编码转换成utf-8altertabletb_anniversaryconverttocharactersetutf8;修改数据库mysql字符编
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
mysql
数据库编码
数据库字符集