广告
返回顶部
首页 > 资讯 > 数据库 >MySQL中文乱码处理_字符集转换处理
  • 635
分享到

MySQL中文乱码处理_字符集转换处理

2024-04-02 19:04:59 635人浏览 独家记忆
摘要

-- 中文乱码修复 -- 查看Mysql服务参数设置mysql> show variables like '%character%';+--------------------------+-----

-- 中文乱码修复

-- 查看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 | /usr/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.03 sec)

-- 查看建库的默认字符集
show create database test;

-- 查看建表的默认字符集
show create table yjdb;

-- 修复为utf8字符集
ALTER DATABASE db_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE tb_name DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

-- root用户执行查询,把结果执行,把不统一的库和表及字段的字符集统一为utf8
-- 修改全库中建库默认字符集
select 'ALTER DATABASE '||db||' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;' from mysql.db where db not in ('infORMation_schema','mysql','test','performance_schema');
select concat('ALTER DATABASE ',db,' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;') from mysql.db where db not in ('information_schema','mysql','test','performance_schema');

-- 修改全库中建表默认字符集
select 'ALTER TABLE '||table_schema||'.'||table_name||' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;' as alter_sql from information_schema.TABLES where table_schema not in ('information_schema','mysql','test','performance_schema') and table_collation != 'utf8_general_ci';
select concat('ALTER TABLE ',table_schema,'.',table_name,' DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;') as alter_sql from information_schema.TABLES where table_schema not in ('information_schema','mysql','test','performance_schema') and table_collation != 'utf8_general_ci';

-- 修改全库中表的列属性为latin1的字符集为默认,请确认后执行。
-- select * from information_schema.COLUMNS where table_schema='tss';
select 'alter table '||TABLE_SCHEMA||'.'||table_name||' change '||column_name||' '||column_name||' '||column_type||' default '||''''||column_default||''''||' comment '||''''||column_comment||''''||';' as alter_sql from information_schema.COLUMNS where table_schema not in ('information_schema','mysql','test','performance_schema') and CHARACTER_SET_NAME='latin1' and is_nullable='yes' and column_default is not null
uNIOn all
select 'alter table '||TABLE_SCHEMA||'.'||table_name||' change '||column_name||' '||column_name||' '||column_type||' comment '||''''||column_comment||''''||';' as alter_sql from information_schema.COLUMNS where table_schema not in ('information_schema','mysql','test','performance_schema') and CHARACTER_SET_NAME='latin1' and is_nullable='yes' and column_default is null
union all
select 'alter table '||TABLE_SCHEMA||'.'||table_name||' change '||column_name||' '||column_name||' '||column_type||' not null default '||''''||column_default||''''||' comment '||''''||column_comment||''''||';' as alter_sql from information_schema.COLUMNS where table_schema not in ('information_schema','mysql','test','performance_schema') and CHARACTER_SET_NAME='latin1' and is_nullable='no' and column_default is not null
union all
select 'alter table '||TABLE_SCHEMA||'.'||table_name||' change '||column_name||' '||column_name||' '||column_type||' not null '||' comment '||''''||column_comment||''''||';' as alter_sql from information_schema.COLUMNS where table_schema not in ('information_schema','mysql','test','performance_schema') and CHARACTER_SET_NAME='latin1' and is_nullable='no' and column_default is null;

-- 为了避免不同环境下出现误差造成影响,可以在建库和表的时候特殊指定字符集

-- 修改库的编码
select concat('ALTER DATABASE ',db,' DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;') from mysql.db_view where db ='xjk_bbs';

-- 修改全库中建表默认字符集
select concat('ALTER TABLE ',table_schema,'.',table_name,' DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;') as alter_sql from information_schema.TABLES where table_schema='xjk_bbs';

-- 修改全库中表的列属性为latin1的字符集为默认,请确认后执行。
-- select * from information_schema.COLUMNS where table_schema='tss';

select concat('alter table ',TABLE_SCHEMA,'.',table_name,' MODIFY COLUMN ',' ',column_name,' ',column_type,' CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ',' default ','''',column_default,'''',' comment ','''',column_comment,'''',';') as alter_sql from information_schema.COLUMNS where table_schema='xjk_bbs' and table_name='aws_question' and column_type not like '%int%' and is_nullable='yes' and column_default is not null
union all
select concat('alter table ',TABLE_SCHEMA,'.',table_name,' MODIFY COLUMN ',' ',column_name,' ',column_type,' CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ',' comment ','''',column_comment,'''',';') as alter_sql from information_schema.COLUMNS where table_schema='xjk_bbs' and table_name='aws_question' and column_type not like '%int%' and is_nullable='yes' and column_default is null
union all
select concat('alter table ',TABLE_SCHEMA,'.',table_name,' MODIFY COLUMN ',' ',column_name,' ',column_type,' CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ',' not null default ','''',column_default,'''',' comment ','''',column_comment,'''',';') as alter_sql from information_schema.COLUMNS where table_schema='xjk_bbs' and table_name='aws_question' and column_type not like '%int%' and is_nullable='no' and column_default is not null
union all
select concat('alter table ',TABLE_SCHEMA,'.',table_name,' MODIFY COLUMN ',' ',column_name,' ',column_type,' CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ',' not null ',' comment ','''',column_comment,'''',';') as alter_sql from information_schema.COLUMNS where table_schema='xjk_bbs' and table_name='aws_question' and column_type not like '%int%' and is_nullable='no' and column_default is null;

您可能感兴趣的文档:

--结束END--

本文标题: MySQL中文乱码处理_字符集转换处理

本文链接: https://www.lsjlt.com/news/42496.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • MySQL中文乱码处理_字符集转换处理
    -- 中文乱码修复 -- 查看MySQL服务参数设置mysql> show variables like '%character%';+--------------------------+-----...
    99+
    2022-10-18
  • 怎么处理数据库中文字符集乱码
    本篇内容主要讲解“怎么处理数据库中文字符集乱码”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么处理数据库中文字符集乱码”吧!一、问题描述  ...
    99+
    2022-10-19
  • Oracle查看字符集,以及中文乱码的处理
    col VALUE format a20select PARAMETER,VALUE  from nls_database_parameters  where PAR...
    99+
    2022-10-18
  • MySQL中如何处理字符集
    这篇文章给大家介绍MySQL中如何处理字符集,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。  MySQL的字符集怎么处理  发送请求  客户端(character_set_client...
    99+
    2022-10-18
  • Golang函数的字符串处理和字符编码转换技巧
    Golang作为一门编程语言,它所提供的字符串处理和字符编码转换功能非常强大和丰富。本文将介绍Golang函数中常用的字符串处理和字符编码转换技巧,帮助读者更好地理解和使用Golang。一、字符串处理字符串连接在Golang中,可以使用"+...
    99+
    2023-05-18
    字符串处理 Golang函数 字符编码转换技巧
  • mysql乱码现象及对字符集的理解
    数据库版本是5.7.17 现象1 Navicat Premium导sqlserver数据到mysql时,发现一些表只导了表结构没有导入数据,一些表导入了部分数据,一些表数据全部导入成功 查找原因: 1....
    99+
    2022-10-18
  • Python 编码转换与中文处理
    Python 编码转换与中文处理python 中的 unicode是让人很困惑、比较难以理解的问题. utf-8是unicode的一种实现方式,unicode、gbk、gb2312是编码字符集.decode是将普通字符串按照参数中的编码格式...
    99+
    2023-01-31
    中文 Python
  • JDBC对Mysql utf8mb4字符集的处理
    在开发微信开放平台, 接入微信公众号的数据时, 关于用户的nickname和文本消息是,大量出现emoji的文本信息, 超时了utf-8字符集的存储范围 在存储数据时, 出现部分特殊字符存储字符串失败. ...
    99+
    2022-10-18
  • 分享一款php代码编码转换工具,轻松处理中文乱码!
    随着互联网的发展,PHP作为脚本语言的应用范围也越来越广泛,尤其在Web开发中,PHP的应用更是日益增多。然而,由于不同的操作系统或编辑器等环境的不同,中文乱码问题也经常困扰着开发者。因此,本文将介绍一款PHP代码编码转换工具,帮助开发者快...
    99+
    2023-05-14
    php
  • Datastage JDBC Connector 中文乱码处理
    在Datastage中,通常处理中文字符编码的时候是通过设置工程、JOB、stage三个级别的NLS但JDBC Connector stage这个组件并没有NLS选项,而是通过 stage里面的“Prope...
    99+
    2022-10-18
  • SUPERSET中文乱码怎么处理
    如果您在SUPERSET中看到了乱码,可能是由于以下原因:1. 数据源中存在非UTF-8编码的字符2. SUPERSET的编码设置不...
    99+
    2023-05-29
    SUPERSET中文乱码 SUPERSET
  • mysql中文字符的问题怎么处理
    这篇文章主要介绍mysql中文字符的问题怎么处理,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!mysql中文字符的问题mysql5.1上成功更改的例子:    &...
    99+
    2022-10-18
  • Linux下mysql字符集问题如何处理
    小编给大家分享一下Linux下mysql字符集问题如何处理,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!4.1之前的 MySQL...
    99+
    2022-10-18
  • python处理html中的转义字符
           最近在用python处理网页数据时,经常遇到一些html转义字符(也叫html字符实体),例如<> 等。字符实体一般是为了表示网页中的预留字符,比如>用>表示,防止被浏览器认为是标签,具体参考w3sc...
    99+
    2023-01-31
    字符 python html
  • python中的字符转运算符、字符串处理方式
    目录字符转运算符、字符串处理默认用法:去除空格字符串支持的运算符及使用python中字符串支持哪些运算符呢?使用方法举例字符转运算符、字符串处理 def CalSingleVals(...
    99+
    2022-11-11
  • 怎么处理html中的换行字符“↵”
    小编给大家分享一下怎么处理html中的换行字符“↵”,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!html是什么html的全称为超文本标记语言,它是一种标记语言,包含了一系列标签.通过这些标签可以将网络上的文档格式统一,使...
    99+
    2023-06-14
  • Nodejs进阶之服务端字符编解码和乱码处理
    写在前面 在web服务端开发中,字符的编解码几乎每天都要打交道。编解码一旦处理不当,就会出现令人头疼的乱码问题。 不少从事node服务端开发的同学,由于对字符编码码相关知识了解不足,遇到问题时,经常会一筹莫...
    99+
    2022-06-04
    进阶 乱码 服务端
  • PHP怎么将字符串转换为字节并进行处理
    本篇内容主要讲解“PHP怎么将字符串转换为字节并进行处理”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“PHP怎么将字符串转换为字节并进行处理”吧!了解字符串和字节字符串是一个包含零个或多个字符的...
    99+
    2023-07-05
  • mysql数据库应用管理+乱码+字符集的示例分析
    这篇文章主要为大家展示了“mysql数据库应用管理+乱码+字符集的示例分析”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“mysql数据库应用管理+乱码+字符集的...
    99+
    2022-10-19
  • SUPERSET中文乱码问题如何处理
    如果在SUPERSET中出现了中文乱码问题,可以尝试以下解决方法:1. 检查数据库字符集:确保数据库字符集和SUPERSET字符集一...
    99+
    2023-05-30
    SUPERSET中文乱码 SUPERSET
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作