mysql命令列修改字元編碼
#1、修改資料庫字元編碼
mysql> alter database mydb character set utf8 ;
2、建立資料庫時,指定資料庫的字元編碼
mysql> create database mydb character set utf8 ;
3、查看mysql資料庫的字元編碼
mysql> show variables like 'character%'; //查询当前mysql数据库的所有属性的字符编码
+--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | latin1 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+
4、修改mysql資料庫的字元編碼
修改字元編碼必須要修改mysql的設定檔my.cnf,然後重啟才能生效
通常需要修改my.cnf的以下幾個地方:
【client】下面,加上default-character-set=utf8,或character_set_client= utf8
【mysqld】下面,加上character_set_server = utf8 ;
因為以上配置,mysql預設是latin1,如果只是透過命令列客戶端,mysql重啟之後就不起作用了。
如下是客戶端命令列修改方式,不建議使用
mysql> set character_set_client=utf8 ; mysql> set character_set_connection=utf8 ; mysql> set character_set_database=utf8 ; mysql> set character_set_database=utf8 ; mysql> set character_set_results=utf8 ; mysql> set character_set_server=utf8 ; mysql> set character_set_system=utf8 ; mysql> show variables like 'character%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
相關學習推薦:mysql教學(影片)
以上是mysql怎麼改字元編碼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!