共计 4397 个字符,预计需要花费 11 分钟才能阅读完成。
本篇内容主要讲解“Mysql 数据库怎么查看使用的编码”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让丸趣 TV 小编来带大家学习“Mysql 数据库怎么查看使用的编码”吧!
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 文件中修改配置信息
使用默认的配置信息
本机访问自己的数据库: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, 与数据库编码格式相同
更改配置文件 /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 数据库怎么查看使用的编码”有了更深的了解,不妨来实际操作一番吧!这里是丸趣 TV 网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!