DataGrip MySQL可正确存储表情符号,但将其显示为?

时间:2019-02-21 20:08:08

标签: mysql character-encoding datagrip

我无法在JetBrains DataGrip中查看表情符号。在主编辑器中,表情符号看起来很好,在SQLite数据库查看器中也是如此。但是,在MySQL中,它们显示为?

我已经很努力地找出如何获取表情符号以正确存储在MySQL中。我遵循了许多指南,这些指南告诉您确保将服务器,客户端,连接,数据库,结果,表和列字符集设置为utf8mb4,并将相应的排序规则设置为utf8mb4_unicode_520_ci。我已经这样做了,但结果仍然相同,即MySQL将表情符号显示为?

我仔细检查了变量并得到了以下结果:

character_set_client        utf8mb4
character_set_results       utf8mb4
character_set_connection    utf8mb4
character_set_server        utf8mb4
character_set_database      utf8mb4
collation_server            utf8mb4_unicode_520_ci
collation_connection        utf8mb4_unicode_520_ci
collation_database          utf8mb4_unicode_520_ci

然后我在JetBrains社区遇到一个答案,说您可能必须像这样强制转换编码:

UPDATE content SET data = (_utf8mb4 '') 
WHERE message_id = 45291;

但是,错误仍然存​​在。然后,我发现了这个小宝石,可以显示列的实际十六进制代码值:

SELECT col, HEX(col), LENGTH(col), CHAR_LENGTH(col)
FROM table WHERE id = 1;

结果如下:

col     HEX(col)            LENGTH()    CHAR_LENGTH(col)
    F09F9899F09F9898    8           2

当然,数据列显示表情符号。请注意,这些结果显示在DataGrip的控制台中。当然,十六进制值对应那些表情符号。我用converter进行了测试。

太好了!困难的部分已经完成。 MySQL正确存储了我的数据。 但是当我转到DataGrip中的实际表时,仍然看到的值为??

我在做什么错了?

编辑 以下是用于连接服务器的环境变量:

{
    "allowLoadLocalInfile": true,
    "allowMultiQueries": false,
    "allowNanAndInf": false,
    "allowUrlInLocalInfile": false,
    "alwaysSendSetIsolation": true,
    "autoClosePStmtStreams": false,
    "replicationConnectionGroup": "",
    "allowMasterDownConnections": false,
    "allowSlaveDownConnections": false,
    "readFromMasterWhenNoSlaves": false,
    "autoDeserialize": false,
    "autoGenerateTestcaseScript": false,
    "autoReconnect": true,
    "autoReconnectForPools": false,
    "blobSendChunkSize": 1048576,
    "autoSlowLog": true,
    "blobsAreStrings": false,
    "functionsNeverReturnBlobs": false,
    "cacheCallableStmts": false,
    "cachePrepStmts": false,
    "cacheResultsSetMetadata": false,
    "serverConfigCacheFactory": "com.mysql.jdbc.PerVmServerConfigCacheFactory",
    "cacheServerConfiguration": false,
    "callableStmtCacheSize": 100,
    "capitalizeTypeNames": true,
    "characterEncoding": "UTF-8",
    "characterSetResults": "UTF-8",
    "connectionAttributes": "",
    "clientInfoProvider": "com.mysql.jdbc.JDBC4CommentClientInfoProvider",
    "clobberStreamingResults": false,
    "clobCharacterEncoding": "",
    "compensateOnDuplicateKeyUpdateCounts": false,
    "connectionCollation": "",
    "connectionLifecycleInterceptors": "",
    "connectTimeout": 0,
    "continueBatchOnError": true,
    "createDatabaseIfNotExist": false,
    "defaultFetchSize": 0,
    "useServerPrepStmts": false,
    "dontTrackOpenResources": false,
    "dumpQueriesOnException": false,
    "dynamicCalendars": false,
    "elideSetAutoCommits": false,
    "emptyStringsConvertToZero": true,
    "emulateLocators": false,
    "emulateUnsupportedPstmts": true,
    "enablePacketDebug": false,
    "enableQueryTimeouts": true,
    "explainSlowQueries": false,
    "exceptionInterceptors": "",
    "failOverReadOnly": true,
    "gatherPerfMetrics": false,
    "generateSimpleParameterMetadata": false,
    "holdResultsOpenOverStatementClose": false,
    "includeInnodbStatusInDeadlockExceptions": false,
    "includeThreadDumpInDeadlockExceptions": false,
    "includeThreadNamesAsStatementComment": false,
    "ignoreNonTxTables": false,
    "initialTimeout": 2,
    "interactiveClient": false,
    "jdbcCompliantTruncation": true,
    "largeRowSizeThreshold": 2048,
    "loadBalanceStrategy": "random",
    "serverAffinityOrder": "",
    "loadBalanceBlacklistTimeout": 0,
    "loadBalancePingTimeout": 0,
    "loadBalanceValidateConnectionOnSwapServer": false,
    "loadBalanceConnectionGroup": "",
    "loadBalanceExceptionChecker": "com.mysql.jdbc.StandardLoadBalanceExceptionChecker",
    "loadBalanceSQLStateFailover": "",
    "loadBalanceSQLExceptionSubclassFailover": "",
    "loadBalanceEnableJMX": false,
    "loadBalanceHostRemovalGracePeriod": 15000,
    "loadBalanceAutoCommitStatementRegex": "",
    "loadBalanceAutoCommitStatementThreshold": 0,
    "localSocketAddress": "",
    "locatorFetchBufferSize": 1048576,
    "logger": "com.mysql.jdbc.log.StandardLogger",
    "logSlowQueries": false,
    "logXaCommands": false,
    "maintainTimeStats": true,
    "maxQuerySizeToLog": 2048,
    "maxReconnects": 3,
    "retriesAllDown": 120,
    "maxRows": -1,
    "metadataCacheSize": 50,
    "netTimeoutForStreamingResults": 600,
    "noAccessToProcedureBodies": false,
    "noDatetimeStringSync": false,
    "noTimezoneConversionForTimeType": false,
    "noTimezoneConversionForDateType": true,
    "cacheDefaultTimezone": true,
    "nullCatalogMeansCurrent": true,
    "nullNamePatternMatchesAll": true,
    "packetDebugBufferSize": 20,
    "padCharsWithSpace": false,
    "paranoid": false,
    "pedantic": false,
    "pinGlobalTxToPhysicalConnection": false,
    "populateInsertRowWithDefaultValues": false,
    "prepStmtCacheSize": 25,
    "prepStmtCacheSqlLimit": 256,
    "parseInfoCacheFactory": "com.mysql.jdbc.PerConnectionLRUFactory",
    "processEscapeCodesForPrepStmts": true,
    "profilerEventHandler": "com.mysql.jdbc.profiler.LoggingProfilerEventHandler",
    "profileSql": "",
    "profileSQL": false,
    "propertiesTransform": "",
    "queriesBeforeRetryMaster": 50,
    "queryTimeoutKillsConnection": false,
    "reconnectAtTxEnd": false,
    "relaxAutoCommit": false,
    "reportMetricsIntervalMillis": 30000,
    "requireSSL": false,
    "resourceId": "",
    "resultSetSizeThreshold": 100,
    "retainStatementAfterResultSetClose": false,
    "rewriteBatchedStatements": false,
    "rollbackOnPooledClose": true,
    "roundRobinLoadBalance": false,
    "runningCTS13": false,
    "secondsBeforeRetryMaster": 30,
    "selfDestructOnPingSecondsLifetime": 0,
    "selfDestructOnPingMaxOperations": 0,
    "replicationEnableJMX": false,
    "serverTimezone": "",
    "sessionVariables": ,
    "slowQueryThresholdMillis": 2000,
    "slowQueryThresholdNanos": 0,
    "socketFactory": "com.mysql.jdbc.StandardSocketFactory",
    "socksProxyHost": "",
    "socksProxyPort": 1080,
    "socketTimeout": 0,
    "statementInterceptors": "",
    "strictFloatingPoint": false,
    "strictUpdates": true,
    "overrideSupportsIntegrityEnhancementFacility": false,
    "tcpNoDelay": true,
    "tcpKeepAlive": true,
    "tcpRcvBuf": 0,
    "tcpSndBuf": 0,
    "tcpTrafficClass": 0,
    "tinyInt1isBit": false,
    "traceProtocol": false,
    "treatUtilDateAsTimestamp": true,
    "transformedBitIsBoolean": false,
    "useBlobToStoreUTF8OutsideBMP": false,
    "utf8OutsideBmpExcludedColumnNamePattern": "",
    "utf8OutsideBmpIncludedColumnNamePattern": "",
    "useCompression": false,
    "useColumnNamesInFindColumn": false,
    "useConfigs": "",
    "useCursorFetch": false,
    "useDynamicCharsetInfo": true,
    "useDirectRowUnpack": true,
    "useFastIntParsing": true,
    "useFastDateParsing": true,
    "useHostsInPrivileges": true,
    "useInformationSchema": false,
    "useJDBCompliantTimezoneShift": false,
    "useLocalSessionState": false,
    "useLocalTransactionState": false,
    "useLegacyDatetimeCode": true,
    "sendFractionalSeconds": true,
    "useNanosForElapsedTime": false,
    "useOldAliasMetadataBehavior": false,
    "useOldUTF8Behavior": false,
    "useOnlyServerErrorMessages": true,
    "useReadAheadInput": true,
    "useSqlStateCodes": true,
    "useSSL": false,
    "useSSPSCompatibleTimezoneShift": false,
    "useStreamLengthsInPrepStmts": true,
    "useTimezone": false,
    "ultraDevHack": false,
    "useUnbufferedInput": true,
    "useUnicode": true,
    "useUsageAdvisor": false,
    "yearIsDateType": false,
    "zeroDateTimeBehavior": "convertToNull",
    "useJvmCharsetConverters": false,
    "useGmtMillisForDatetimes": false,
    "dumpMetadataOnColumnNotFound": false,
    "clientCertificateKeyStoreUrl": "",
    "trustCertificateKeyStoreUrl": "",
    "clientCertificateKeyStoreType": "JKS",
    "clientCertificateKeyStorePassword": "",
    "trustCertificateKeyStoreType": "JKS",
    "trustCertificateKeyStorePassword": "",
    "verifyServerCertificate": true,
    "useAffectedRows": false,
    "passwordCharacterEncoding": "",
    "maxAllowedPacket": -1,
    "authenticationPlugins": "",
    "disabledAuthenticationPlugins": "",
    "defaultAuthenticationPlugin": "com.mysql.jdbc.authentication.MysqlNativePasswordPlugin",
    "disconnectOnExpiredPasswords": true,
    "getProceduresReturnsFunctions": true,
    "detectCustomCollations": false,
    "serverRSAPublicKeyFile": "",
    "allowPublicKeyRetrieval": false,
    "dontCheckOnDuplicateKeyUpdateInSQL": false,
    "readOnlyPropagatesToServer": true,
    "enabledSSLCipherSuites": "",
    "enabledTLSProtocols": "",
    "enableEscapeProcessing": true
}

编辑 以下是一些屏幕截图,可帮助您了解我所看到的内容:

当我通过数据库表视图(?代替表情符号)导航到记录时: no-emoji

当我执行查询以选择相同的记录并在控制台中查看它时(表情符号显示为表情符号): emoji-console

1 个答案:

答案 0 :(得分:0)

在DataGrip中尚不可能,但是可以在实现此功能后解决:https://youtrack.jetbrains.com/issue/DBE-2606