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