mysql全局编码格式修改和数据库实例的编码格式修改

修改数据库全局编码格式:
1.命令行登录mysql 
C:\Users\Administrator>mysql -u root -p 
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 3 
Server version: 5.6.20 MySQL Community Server (GPL) 

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. 

Oracle is a registered trademark of Oracle Corporation and/or its 
affiliates. Other names may be trademarks of their respective 
owners. 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 


2. 查看mysql全局编码格式 
mysql> show variables like 'character%'; 
+--------------------------+---------------------------------------------------- 
-----+ 
| Variable_name | Value 

+--------------------------+---------------------------------------------------- 
-----+ 
| character_set_client | gbk 

| character_set_connection | gbk 

| character_set_database | latin1 

| character_set_filesystem | binary 

| character_set_results | gbk 

| character_set_server | latin1 

| character_set_system | utf8 

| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.6\share\chars 
ets\ | 


3.把mysql的全局编码格式修改为utf8(character_set_filesystem=binary 不用修改) 
mysql> set character_set_client = utf8; 
Query OK, 0 rows affected (0.04 sec) 

mysql> set character_set_connection = utf8 
Query OK, 0 rows affected (0.00 sec) 

mysql> set character_set_database = utf8; 
Query OK, 0 rows affected (0.00 sec) 

mysql> set character_set_filesystem = utf8; 
Query OK, 0 rows affected (0.00 sec) 

mysql> set character_set_results = utf8; 
Query OK, 0 rows affected (0.00 sec) 

mysql> set character_set_server = utf8; 
Query OK, 0 rows affected (0.00 sec) 


4.查看修改后的mysql全局编码格式 
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 | D:\Program Files\MySQL\MySQL Server 5.6\share\chars 
ets\ | 
+--------------------------+---------------------------------------------------- 
-----+ 
8 rows in set (0.00 sec) 




修改某个数据库实例的编码: 
1.选择数据库实例 
mysql> use mysql; 
Database changed 

2.查看数据库实例信息; 
mysql> status; 
-------------- 
mysql Ver 14.14 Distrib 5.6.20, for Win32 (x86) 

Connection id: 3 
Current database: mysql 
Current user:  root@localhost  
SSL: Not in use 
Using delimiter: ; 
Server version: 5.6.20 MySQL Community Server (GPL) 
Protocol version: 10 
Connection: localhost via TCP/IP 
Server characterset: latin1 
Db characterset: latin1 
Client characterset: gbk 
Conn. characterset: gbk 
TCP port: 3306 
Uptime: 38 min 45 sec 

Threads: 1 Questions: 49 Slow queries: 0 Opens: 67 Flush tables: 1 Open tab 
les: 60 Queries per second avg: 0.021 
-------------- 

3.修改数据库编码; 
mysql> set names 'utf8'; 
Query OK, 0 rows affected (0.00 sec) 

4.查看修改编码格式后的数据库信息; 
mysql> status; 
-------------- 
mysql Ver 14.14 Distrib 5.6.20, for Win32 (x86) 

Connection id: 3 
Current database: mysql 
Current user:  root@localhost  
SSL: Not in use 
Using delimiter: ; 
Server version: 5.6.20 MySQL Community Server (GPL) 
Protocol version: 10 
Connection: localhost via TCP/IP 
Server characterset: latin1 
Db characterset: latin1 
Client characterset: utf8 
Conn. characterset: utf8 
TCP port: 3306 
Uptime: 1 hour 48 min 16 sec 

Threads: 1 Questions: 63 Slow queries: 0 Opens: 67 Flush tables: 1 Open tab 
les: 60 Queries per second avg: 0.009 
--------------

你可能感兴趣的:(mysql全局编码格式修改和数据库实例的编码格式修改)