mysql命令行修改字符編碼

一、修改數據庫字符編碼mysql

mysql> alter database mydb character set utf8 ;sql

二、建立數據庫時,指定數據庫的字符編碼數據庫

mysql> create database mydb character set utf8 ;編碼

三、查看mysql數據庫的字符編碼命令行

mysql> show variables like 'character%'; //查詢當前mysql數據庫的全部屬性的字符編碼server

+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+io

四、修改mysql數據庫的字符編碼字符編碼

修改字符編碼必需要修改mysql的配置文件my.cnf,而後重啓才能生效cli

一般須要修改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)

相關文章
相關標籤/搜索