GVKun编程网logo

在Hebrew characters插入MySQL表时获取问号(mysql怎么向表中输入数据)

16

在本文中,我们将为您详细介绍在Hebrewcharacters插入MySQL表时获取问号的相关知识,并且为您解答关于mysql怎么向表中输入数据的疑问,此外,我们还会提供一些关于A2-05-01.My

在本文中,我们将为您详细介绍在Hebrew characters插入MySQL表时获取问号的相关知识,并且为您解答关于mysql怎么向表中输入数据的疑问,此外,我们还会提供一些关于A2-05-01.MySQL Character Set、Can''t initialize character set utf8 (path: /usr/share/mysql/charsets/)、Can''t initialize character set utf8mb4 (path: /usr/share/mysql/charsets/)、HTTP400:Invalid character found in the request target. The valid characters are defined in RFC 7230的有用信息。

本文目录一览:

在Hebrew characters插入MySQL表时获取问号(mysql怎么向表中输入数据)

在Hebrew characters插入MySQL表时获取问号(mysql怎么向表中输入数据)

我正在使用Netbeans使用Java,JSP构建Web应用程序,该应用程序处理带有希伯来语字段的数据库。

DDL如下:

String cityTable = "CREATE TABLE IF NOT EXISTS hebrew_test.table ("                            +"id int(11) NOT NULL AUTO_INCREMENT,"                            +"en varchar(30) NOT NULL,"                            +"he varchar(30) COLLATE utf8_bin NOT NULL,"                            +"PRIMARY KEY (id)"                            +") ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1;";String insert = "INSERT INTO hebrew_test.table (en, he) VALUES (''A'',''a'')";String insert2 = "INSERT INTO hebrew_test.table (en, he) VALUES (''B'',''ב'')";String insert3 = "INSERT INTO hebrew_test.table (en, he) VALUES (''C'',''אבג'')";executeSQLCommand(cityTable);executeSQLCommand(insert);executeSQLCommand(insert2);executeSQLCommand(insert3);

我得到的输出表格:

1   A   a2   B   ?3   C   ???

代替:

1   A   a2   B   ב3   C   אבג

您还定义了要在UTF8_bin上面的代码中看到的表。

答案1

小编典典

您需要告诉JDBC驱动程序在将代表SQL查询的字符解码为字节时使用UTF-8编码。您可以通过向JDBC连接URL
添加参数useUnicode=yescharacterEncoding=UTF-8查询参数来实现。

jdbc:mysql://localhost:3306/db_name?useUnicode=yes&characterEncoding=UTF-8

否则,它将使用操作系统平台的默认字符集。MySQL
JDBC驱动程序本身很清楚客户端(运行JDBC代码的地方)和服务器端(数据库表的地方)使用的编码。DB表使用的字符集未涵盖的任何字符都将被问号替换。

A2-05-01.MySQL Character Set

A2-05-01.MySQL Character Set

转载自:http://www.mysqltutorial.org/mysql-character-set/

Home Basic MySQL Tutorial / MySQL Character Set

MySQL Character Set

 

Summary: in this tutorial, you will learn about MySQL character set. After the tutorial, you will know how to get all character sets in MySQL, how to convert strings between character sets, and how to configure proper character sets for client connections.

Introduction to MySQL character set

A MySQL character set is a set of characters that are legal in a string. For example, we have an alphabet with letters from a  to z.We assign each letter a number, for example,  a = 1b = 2 etc. The letter  a is a symbol, and the number 1  that associates with the letter a  is the encoding. The combination of all letters from a to z and their corresponding encodings is a character set.

Each character set has one or more collations that define a set of rules for comparing characters within the character set. Check it out the MySQL collation tutorial to learn about the collations in MySQL.

MySQL supports various character sets that allow you to store almost every character in a string. To get all available character sets in MySQL database server, you use the SHOW CHARACTER SET  statement as follows:

 
1
SHOW CHARACTER SET;

mysql character set

The default character set in MySQL is latin1. If you want to store characters from multiple languages in a single column, you can use Unicode character sets, which is utf8 or ucs2.

The values in the Maxlen column specify the number of bytes that a character in a character set holds. Some character sets contain single-byte characters e.g., latin1 , latin2 , cp850 , etc., whereas other character sets contain multi-byte characters.

MySQL provides the LENGTH function to get a length of a string in bytes, and the CHAR_LENGTH function to get the length of a string in characters. If a string contains the multi-bytes character, the result of the LENGTH function is greater than the result of the CHAR_LENGTH() function. See the following example:

 
1
2
SET @str = CONVERT(''MySQL Character Set'' USING ucs2);
SELECT LENGTH(@str), CHAR_LENGTH(@str);

mysql convert character set

The CONVERT function converts a string into a specific character set. In this example, it converts the character set of the MySQL Character Set  string into ucs2 . Because ucs2 character set contains 2-byte characters, therefore the length of the @str  string in bytes is greater than its length in characters.

Notice that some character sets contain multi-byte characters,  but their strings may contain only single-byte characters e.g., utf8  as shown in the following statements:

 
1
2
SET @str = CONVERT(''MySQL Character Set'' USING utf8);
SELECT LENGTH(@str), CHAR_LENGTH(@str);

single-byte character set

However, if a utf8 string contains special character e.g., ü  in the pingüino string; its length in bytes is different, see the following example:

 
1
2
SET @str = CONVERT(''pingüino'' USING utf8);
SELECT LENGTH(@str), CHAR_LENGTH(@str);

 

unicode character set

Converting between different character sets

MySQL provides two functions that allow you to convert strings between different character sets: CONVERT and CAST. We have used the CONVERT function several times in the above examples.

The syntax of the CONVERT function is as follows:

 
1
CONVERT(expression USING character_set_name)

The CAST function is similar to the CONVERT function. It converts a string to a different character set:

 
1
CAST(string AS character_type CHARACTER SET character_set_name)

Take a look at the following example of using the CAST  function:

 
1
SELECT CAST(_latin1''MySQL character set'' AS CHAR CHARACTER SET utf8);

 

Setting character sets for client connections

When an application exchanges data with a MySQL database server, the default character set is latin1. However, if the database stores Unicode strings in the utf8 character set, using the latin1 character set in the application would not be sufficient. Therefore, the application needs to specify a proper character set when it connects to MySQL database server.

To configure a character set for a client connection, you can do one of the following ways:

  • Issue the SET NAME  statement after the client connected to the MySQL database server. For example, to set a Unicode character set utf8, you use the following statement:

 

 
1
SET NAMES ''utf8'';

 

  • If the application supports the --default-character-set  option, you can use it to set the character set. For example, mysql client tool supports --default-character-set  and you can set it up in the configuration file as follows:

 

 
1
2
[mysql]
default-character-set=utf8

 

  • Some MySQL connectors allow you to set character set, for example, if you use PHP PDO, you can set the character set in the data source name as follows:

 

 
1
$dsn ="mysql:host=$host;dbname=$db;charset=utf8";

Regardless of which way you use, make sure that the character set used by the application matches with the character set stored in the MySQL database server.

In this tutorial, you have learned about MySQL character set, how to convert strings between character sets and how to configure proper character sets for client connections.

Can''t initialize character set utf8 (path: /usr/share/mysql/charsets/)

Can''t initialize character set utf8 (path: /usr/share/mysql/charsets/)

【1】Can''t initialize character set utf8] (path: /usr/share/mysql/charsets/) 

【1.1】
报错信息:
  
  mysql: Character set ''utf8]'' is not a compiled character set and is not specified in the ''/usr/share/mysql/charsets/Index.xml'' file
  mysql: Character set ''utf8]'' is not a compiled character set and is not specified in the ''/usr/share/mysql/charsets/Index.xml'' file
  ERROR 2019 (HY000): Can''t initialize character set utf8] (path: /usr/share/mysql/charsets/) 
 
【1.2】验证文件字符集,验证mysql支持的字符集;
  查看字符串是否是mysql支持的,比如把文件放到notpad++中去查看。
  或者进入mysql,查看Mysql支持的字符集有哪些(show charset;)
文件字符集:
  

 

【1.3】usr/share/mysql/charsets/Index.xml

文件:usr/share/mysql/charsets/Index.xml ,看这个文件好像并没有什么卵用。
  

  一看就知道,无法识别解析字符,看看配置文件

【1.4】my.cnf

  

 

   果然,客户端字符集设置有问题,修改好后,解决问题。

  这里因为是 [client]的问题,所以不需要重启mysql,大家可以试试,实在不行再重启 Mysql。

 

【2】Character set ''utf-8'' is not a compiled character set and is not specified

  当出现“Character set ''utf-8'' is not a compiled character set and is not specifie”的错误时,
  将mysql安装目录下的my.ini文件的default-character-set=utf-8更改为default-character-set=utf8即可,
  简单来说就是将"utf-8"更改为"utf8"即可。
 

【3】Mysql:Character set ''utf8mb4'' is not a compiled character set ... 解决方案

连接Mysql时出现如下错误
Mysql:Character set ''utf8mb4'' is not a compiled character set and is not specified in the ''/usr/share/mysql/charsets/Index.xml'' file

解决方法如下:

打开文件/usr/share/mysql/charsets/Index.xml
直接复制文件中utf8的配置,改为utf8mb4后,添加到文件中故障解决,更改方式如下

<charset name="utf8mb4">
  <family>Unicode</family>
  <description>UTF-8 Unicode</description>
  <alias>utf-8</alias>
  <collation name="utf8_general_ci" id="33">
   <flag>primary</flag>
   <flag>compiled</flag>
  </collation>
  <collation name="utf8_bin"  id="83">
    <flag>binary</flag>
    <flag>compiled</flag>
  </collation>
</charset>

 

参考文件

字符集问题: https://blog.csdn.net/ACMAIN_CHM/article/details/4174186

Character set ''utf8mb4'' is not a compiledhttps://blog.51cto.com/yangjingangel/1754413

 

Can''t initialize character set utf8mb4 (path: /usr/share/mysql/charsets/)

Can''t initialize character set utf8mb4 (path: /usr/share/mysql/charsets/)

为了支持 emoj 存储,数据集从 utf8 改成 utf8mb4

环境变量配置如下

Can''t initialize character set utf8mb4 (path: /usr/share/mysql/charsets/)

此问题解决办法如下

yum erase php56w-mysql
yum install php56w-mysqlnd

意思就是需要使用 php-mysqlnd

HTTP400:Invalid character found in the request target. The valid characters are defined in RFC 7230

HTTP400:Invalid character found in the request target. The valid characters are defined in RFC 7230

错误:
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
在这里插入图片描述
错误原因:
参数里面有特殊符号-中括号:[]

在这里插入图片描述

解决办法1:

package com.sccl.business.config;

import org.apache.catalina.connector.Connector;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * tomcat配置类
 *
 * @author zdway
 * @date 2021/1/15 14:21
 */
@Configuration
public class TomcatConfig {

    /**
     * 解决异常信息:(允许参数有|{}[]特殊字符)
     *  java.lang.IllegalArgumentException:
     *      Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
     * @return
     */
    @Bean
    public ConfigurableServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
            @Override
            public void customize(Connector connector) {
                connector.setProperty("relaxedQueryChars", "|{}[]");
            }
        });
        return factory;
    }
}

解决办法2:
使用方法对参数中的特殊符号进行转义

关于在Hebrew characters插入MySQL表时获取问号mysql怎么向表中输入数据的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于A2-05-01.MySQL Character Set、Can''t initialize character set utf8 (path: /usr/share/mysql/charsets/)、Can''t initialize character set utf8mb4 (path: /usr/share/mysql/charsets/)、HTTP400:Invalid character found in the request target. The valid characters are defined in RFC 7230的相关信息,请在本站寻找。

本文标签: