MySQL字符集

long_small發表於2022-10-22

檢視當前字符集


mysql> show global variables like '%server';

+----------------------+-------------------+

| Variable_name        | Value             |

+----------------------+-------------------+

| character_set_server | latin1            |

| collation_server     | latin1_swedish_ci |

+----------------------+-------------------+

2 rows in set (0.00 sec)


設定字符集

mysql> set global character_set_server=gbk;

Query OK, 0 rows affected (0.00 sec)


mysql> show global variables like '%server';

+----------------------+----------------+

| Variable_name        | Value          |

+----------------------+----------------+

| character_set_server | gbk            |

| collation_server     | gbk_chinese_ci |

+----------------------+----------------+

2 rows in set (0.00 sec)



建庫指定字符集:

mysql> create database cms_app  DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

Query OK, 1 row affected (0.00 sec)


show collation like 'utf8%';




create table test(name varchar(30));

Query OK, 0 rows affected (0.01 sec)


mysql> insert into test values('我和我的祖國');

Query OK, 1 row affected (0.02 sec)


mysql> select * from test;

+--------------------+

| name               |

+--------------------+

| 我和我的祖國       |

+--------------------+

1 row in set (0.00 sec)

mysql> show variables like 'character_set_client';

+----------------------+-------+

| Variable_name        | Value |

+----------------------+-------+

| character_set_client | utf8  |

+----------------------+-------+

1 row in set (0.00 sec)



mysql> show global variables like 'character_set\_%';

+--------------------------+--------+

| 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     | utf8   |

| character_set_system     | utf8   |

+--------------------------+--------+

7 rows in set (0.01 sec)

會話級別的

mysql> show variables like 'character_set\_%';

+--------------------------+--------+

| 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     | gbk    |

| character_set_system     | utf8   |

+--------------------------+--------+

7 rows in set (0.00 sec)



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25846553/viewspace-2919807/,如需轉載,請註明出處,否則將追究法律責任。

相關文章