介绍三种查看MySQL字符集的方法
发表于:2025-01-22 作者:千家信息网编辑
千家信息网最后更新 2025年01月22日,MySQL字符集设置系统变量:- character_set_server:默认的内部操作字符集- character_set_client:客户端来源数据使用的字符集- character_set_
千家信息网最后更新 2025年01月22日介绍三种查看MySQL字符集的方法
登陆MySQL数据库:
C:\Users\duansf>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.13 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, 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.
mysql>
一.查看MySQL数据库服务器和数据库MySQL的字符集:
mysql> show variables like '%char%';
+--------------------------+---------------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | gbk |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | C:\Program Files (x86)\MySQL\MySQL Server 5.5\share\charsets\ |
+--------------------------+---------------------------------------------------------------+
8 rows in set (0.00 sec)
二.查看MySQL数据表(table)的MySQL字符集:
mysql> use test
Database changed
mysql> show table status from test like '%work%';
+----------+--------+---------+------------+------+----------------+-------------+-----------------+
--------------+-----------+----------------+---------------------+-------------+------------+-------
----------+----------+----------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length |
Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collat
ion | Checksum | Create_options | Comment |
+----------+--------+---------+------------+------+----------------+-------------+-----------------+
--------------+-----------+----------------+---------------------+-------------+------------+-------
----------+----------+----------------+---------+
| workinfo | InnoDB | 10 | Compact | 1 | 16384 | 16384 | 0 |
32768 | 9437184 | 4 | 2016-03-07 16:13:51 | NULL | NULL | utf8_g
eneral_ci | NULL | | |
+----------+--------+---------+------------+------+----------------+-------------+-----------------+
--------------+-----------+----------------+---------------------+-------------+------------+-------
----------+----------+----------------+---------+
1 row in set (0.00 sec)
三.查看MySQL数据列(column)的MySQL字符集:
mysql> show full columns from workinfo;
+----------+-------------+-----------------+------+-----+---------+----------------+----------------
-----------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges
| Comment |
+----------+-------------+-----------------+------+-----+---------+----------------+----------------
-----------------+---------+
| id | int(10) | NULL | NO | PRI | NULL | auto_increment | select,insert,u
pdate,references | |
| name | varchar(20) | utf8_general_ci | NO | | NULL | | select,insert,u
pdate,references | |
| type | varchar(10) | utf8_general_ci | YES | | NULL | | select,insert,u
pdate,references | |
| address | varchar(50) | utf8_general_ci | YES | | NULL | | select,insert,u
pdate,references | |
| tel | varchar(20) | utf8_general_ci | YES | | NULL | | select,insert,u
pdate,references | |
| wages | int(11) | NULL | YES | | NULL | | select,insert,u
pdate,references | |
| contents | tinytext | utf8_general_ci | YES | | NULL | | select,insert,u
pdate,references | |
| extra | text | utf8_general_ci | YES | | NULL | | select,insert,u
pdate,references | |
+----------+-------------+-----------------+------+-----+---------+----------------+----------------
-----------------+---------+
8 rows in set (0.02 sec)
解决字符集通讯设置不匹配的方法:
(修改默认的character_set_client,character_set_connection,character_set_result)
1. 重新编译mysql和php,mysql加入编译参数 -default-character-set=utf8
2. PHP程序在查询数据库之前,执行mysql_query("set names utf8;");
3.修改my.cnf,在[mysqld]中加入init-connect="set names utf8" (对于超级用户连接该选项无效)
4. 启动mysqld 加入参数 -skip-character-set-client-handshake 忽略客户端字符集
MySQL字符集设置
系统变量:
- character_set_server:默认的内部操作字符集
- character_set_client:客户端来源数据使用的字符集
- character_set_connection:连接层字符集
- character_set_results:查询结果字符集
- character_set_database:当前选中数据库的默认字符集
- character_set_system:系统元数据(字段名等)字符集
- 还有以collation_开头的同上面对应的变量,用来描述字符序。
登陆MySQL数据库:
C:\Users\duansf>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.13 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, 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.
mysql>
一.查看MySQL数据库服务器和数据库MySQL的字符集:
mysql> show variables like '%char%';
+--------------------------+---------------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | gbk |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | C:\Program Files (x86)\MySQL\MySQL Server 5.5\share\charsets\ |
+--------------------------+---------------------------------------------------------------+
8 rows in set (0.00 sec)
二.查看MySQL数据表(table)的MySQL字符集:
mysql> use test
Database changed
mysql> show table status from test like '%work%';
+----------+--------+---------+------------+------+----------------+-------------+-----------------+
--------------+-----------+----------------+---------------------+-------------+------------+-------
----------+----------+----------------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length |
Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collat
ion | Checksum | Create_options | Comment |
+----------+--------+---------+------------+------+----------------+-------------+-----------------+
--------------+-----------+----------------+---------------------+-------------+------------+-------
----------+----------+----------------+---------+
| workinfo | InnoDB | 10 | Compact | 1 | 16384 | 16384 | 0 |
32768 | 9437184 | 4 | 2016-03-07 16:13:51 | NULL | NULL | utf8_g
eneral_ci | NULL | | |
+----------+--------+---------+------------+------+----------------+-------------+-----------------+
--------------+-----------+----------------+---------------------+-------------+------------+-------
----------+----------+----------------+---------+
1 row in set (0.00 sec)
三.查看MySQL数据列(column)的MySQL字符集:
mysql> show full columns from workinfo;
+----------+-------------+-----------------+------+-----+---------+----------------+----------------
-----------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges
| Comment |
+----------+-------------+-----------------+------+-----+---------+----------------+----------------
-----------------+---------+
| id | int(10) | NULL | NO | PRI | NULL | auto_increment | select,insert,u
pdate,references | |
| name | varchar(20) | utf8_general_ci | NO | | NULL | | select,insert,u
pdate,references | |
| type | varchar(10) | utf8_general_ci | YES | | NULL | | select,insert,u
pdate,references | |
| address | varchar(50) | utf8_general_ci | YES | | NULL | | select,insert,u
pdate,references | |
| tel | varchar(20) | utf8_general_ci | YES | | NULL | | select,insert,u
pdate,references | |
| wages | int(11) | NULL | YES | | NULL | | select,insert,u
pdate,references | |
| contents | tinytext | utf8_general_ci | YES | | NULL | | select,insert,u
pdate,references | |
| extra | text | utf8_general_ci | YES | | NULL | | select,insert,u
pdate,references | |
+----------+-------------+-----------------+------+-----+---------+----------------+----------------
-----------------+---------+
8 rows in set (0.02 sec)
解决字符集通讯设置不匹配的方法:
(修改默认的character_set_client,character_set_connection,character_set_result)
1. 重新编译mysql和php,mysql加入编译参数 -default-character-set=utf8
2. PHP程序在查询数据库之前,执行mysql_query("set names utf8;");
3.修改my.cnf,在[mysqld]中加入init-connect="set names utf8" (对于超级用户连接该选项无效)
4. 启动mysqld 加入参数 -skip-character-set-client-handshake 忽略客户端字符集
字符
字符集
数据
数据库
参数
变量
客户
客户端
系统
查询
编译
方法
字段
开头
数据表
服务器
来源
用户
程序
结果
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
科技部长视察天溯互联网
浪潮服务器待外管理
软件开发内容方向明细
企业使用软件开发评判标准
深圳安卓软件开发哪家便宜
怎么通过客户端找到服务器
数据库设置外键
衢州服务器在哪个位置
凤城世超网络技术在哪里
服务器管理器删除服务
网站acc数据库怎么建
四川上略网络技术有限公司
存储服务器概述
如何将电脑做成存储照片的服务器
ftp和数据库是一样的吗
为了你的网络安全请登录
软件开发 流程图软件
电子商务系统创建数据库
物流电脑用的什么软件开发
服务器主动发数据到app
海岛奇兵在哪个服务器可以下载
泉州中专网络技术
锡山区机电软件开发售后服务
新炬网络技术
淮北专业的服务器机箱
视频管理服务器8700
ddos考网络安全试题库
网络安全课程设计结论
河北常规软件开发设计
违反网络安全法的实例