快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

Mysql数据库怎么查看使用的编码

本篇内容主要讲解“MySQL数据库怎么查看使用的编码”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Mysql数据库怎么查看使用的编码”吧!

从事德阳电信服务器托管,服务器租用,云主机,雅安服务器托管主机域名,CDN,网络代维等服务。

Mysql数据库默认编码

查看使用的编码

1.  使用status查看

mysql> status

--------------
mysql  Ver 14.14 Distrib 5.6.44, for Linux (x86_64) using  EditLine wrapper

Connection id:      22
Current database:   
Current user:       root@localhost
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     5.6.44 MySQL Community Server (GPL)
Protocol version:   10
Connection:     Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:        /var/run/mysqld/mysqld.sock
Uptime:         6 hours 31 min 31 sec

Threads: 1  Questions: 905  Slow queries: 1  Opens: 74  Flush tables: 1  Open tables: 67  Queries per second avg: 0.038
--------------

Server characterset:    latin1
Db     characterset:    latin1  (数据库编码格式)
Client characterset:    utf8        (客户端连接进来的编码格式)
Conn.  characterset:    utf8        (接入的编码格式)

2. 使用show variables

show variables like 'character'

mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

/etc/my.cnf文件中修改配置信息

  1. 使用默认的配置信息

    • 本机访问自己的数据库:Server characterset:    latin1

      status

      Server characterset:   latin1
      Db     characterset:   latin1
      Client characterset:   utf8
      Conn.  characterset:   utf8

      show variables like 'character%'

      +--------------------------+----------------------------+
      
      | Variable_name            | Value                      |
      
      +--------------------------+----------------------------+
      
      | character_set_client     | utf8                       |
      
      | character_set_connection | utf8                       |
      
      | character_set_database   | latin1                     |
      
      | character_set_filesystem | binary                     |
      
      | character_set_results    | utf8                       |
      
      | character_set_server     | latin1                     |
      
      | character_set_system     | utf8                       |
      
      | character_sets_dir       | /usr/share/mysql/charsets/ |
      
      +--------------------------+----------------------------+

      创建一个数据库encodtest,查看其编码信息

      Server characterset:   latin1
      Db     characterset:   latin1
      Client characterset:   utf8
      Conn.  characterset:   utf8
      mysql> show variables like 'character%';
      +--------------------------+----------------------------+
      | Variable_name            | Value                      |
      +--------------------------+----------------------------+
      | character_set_client     | utf8                       |
      | character_set_connection | utf8                       |
      | character_set_database   | latin1                     |
      | character_set_filesystem | binary                     |
      | character_set_results    | utf8                       |
      | character_set_server     | latin1                     |
      | character_set_system     | utf8                       |
      | character_sets_dir       | /usr/share/mysql/charsets/ |
      +--------------------------+----------------------------+

      character_set_database是数据库的编码格式

      创建一个test表查看其默认的编码格式

      show create table test;

      +-------+-------------------------------
      | Table | Create Table                                                                                               |
      +-------+-------------------------------
      | test  | CREATE TABLE `test` (
      `id` int(11) NOT NULL,
      PRIMARY KEY (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
      +-------+-------------------------------

      DEFAULT CHARSET=latin1默认的编码格式是latin1,与数据库编码格式相同

  2. 更改配置文件/etc/my.cnf

    添加设置:

    [client]
    default-character-set = utf8
    [mysqld]
    character-set-server=utf8
    collation-server=utf8_unicode_ci
    • 本机进入数据库

      查看编码格式:

      status

      Server characterset:   utf8
      Db     characterset:   utf8
      Client characterset:   utf8
      Conn.  characterset:   utf8

      show variables like 'char%';

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

      创建数据库查看其编码

      与上面相同

      创建表查看编码:

      +-------+------------------------------------------------------
      | Table | Create Table                                                                                                                     |
      +-------+------------------------------------------------------
      | test  | CREATE TABLE `test` (
      `id` int(11) NOT NULL,
      PRIMARY KEY (`id`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |
      +-------+-----------------------------------------------------

      DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci默认的编码格式与配置相同

到此,相信大家对“Mysql数据库怎么查看使用的编码”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!


文章名称:Mysql数据库怎么查看使用的编码
路径分享:http://6mz.cn/article/ispjgc.html

其他资讯