Mysql數據庫是一個開源的數據庫,應用非常廣泛。以下是修改mysql數據庫的字符編碼的操作過程和將表的字符編碼轉換成utf-8的方法,需要的朋友可以參考下.
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
,查詢當前表各個字段的詳細信息:show full columns from table_name;