jumpserver 報錯"Incorrect string value

申明

本文全部內容參考自jumpserver記錄命令沒法入庫問題 #1773mysql

簡介

jumpserver 1.4.0在jumpserver.log中大量報錯,錯誤日誌git

File "/opt/jumpserver/apps/terminal/api.py", line 246, in create
    ok = self.command_store.bulk_save(serializer.validated_data)
  File "/opt/jumpserver/apps/terminal/backends/command/db.py", line 38, in bulk_save
    return self.model.objects.bulk_create(_commands)
django.db.utils.OperationalError: (1366, "Incorrect string value: '\\xF2\\xB7\\xAF\\x8A.\\xEF...' for column 'output' at row 1")

究其緣由,是因爲數據庫中要插入emoji表情符號。官網上安裝教程中創建的是uft-8字符集的數據庫,而要支持emoji須要使用utf8mb4,所以報錯。github

解決

解決方法包括兩部:修改數據庫字符集,修改jumpserver 數據庫鏈接參數sql

  1. 修改字符集
use jumpserver;
SET character_set_client = utf8mb4;
SET character_set_results = utf8mb4;
SET character_set_connection = utf8mb4;
  1. 修改jumpserver數據庫鏈接參數

edit apps/jumpserver/settings.py 修改DATABASES項目數據庫

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.{}'.format(CONFIG.DB_ENGINE),
        'NAME': CONFIG.DB_NAME,
        'HOST': CONFIG.DB_HOST,
        'PORT': CONFIG.DB_PORT,
        'USER': CONFIG.DB_USER,
        'PASSWORD': CONFIG.DB_PASSWORD,
        'ATOMIC_REQUESTS': True,
        'OPTIONS': {'charset': 'utf8mb4'},
    }
}
相關文章
相關標籤/搜索