Common SQL Errors

MySQL Error 3221: ER_AUDIT_LOG_JSON_USER_NAME_CANNOT_BE_EMPTY - How to Fix and Prevent

Galaxy Team
August 8, 2025

MySQL cannot write an audit log entry in JSON format because the user name field is empty, triggering error 3221.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 3221 ER_AUDIT_LOG_JSON_USER_NAME_CANNOT_BE_EMPTY?

ER_AUDIT_LOG_JSON_USER_NAME_CANNOT_BE_EMPTY (MySQL 3221) appears when the Enterprise Audit plugin tries to write a JSON log entry with a blank user name. Validate the CURRENT_USER value, audit log filters, and connector settings, then supply or substitute a non-empty user name to resolve the issue.

Error Highlights

Typical Error Message

ER_AUDIT_LOG_JSON_USER_NAME_CANNOT_BE_EMPTY

Error Type

Configuration Error

Language

MySQL

Symbol

ER_AUDIT_LOG_JSON_USER_NAME_CANNOT_BE_EMPTY was added in 5.7.22.

Error Code

3221

SQL State

HY000

Explanation

Table of Contents

What is MySQL error 3221 ER_AUDIT_LOG_JSON_USER_NAME_CANNOT_BE_EMPTY?

Error 3221 occurs when the MySQL Enterprise Audit plugin attempts to write a JSON audit log record whose user_name field is blank. Because the JSON schema requires a non-empty value, the write fails and the server returns SQLSTATE HY000 with the message "User cannot be empty."

The condition was introduced in MySQL 5.7.22 and exists in all later 5.7, 8.0 and 8.1 releases. It can appear during connection, statement execution, or administrative events if the audit filter or connector leaves the user name unset.

What Causes This Error?

Misconfigured audit filters that match an empty string, proxy user setups that strip CURRENT_USER, and failed LDAP or PAM authentications commonly leave the user field blank. When the audit plugin serializes the event in JSON format, the validation layer refuses the record and raises error 3221.

The error may also surface when external connection pools reuse sessions after a failed login, or when accounts are created with the deprecated anonymous syntax and then audited.

How to Fix ER_AUDIT_LOG_JSON_USER_NAME_CANNOT_BE_EMPTY

First verify that CURRENT_USER returns a value for the session that triggered the error. If it returns an empty string, reset authentication plugins or recreate the account with a valid user name.

Next inspect audit filters created with mysql.audit_json_filter_set() and remove any rules that output an empty user. Finally, test the fix by reconnecting and confirming that the audit log writes without errors.

Common Scenarios and Solutions

Anonymous connections: revoke USAGE on ''@'host' and require a named account. Proxy users: set PROXY privilege correctly so proxied sessions have a definite user identity. Programmatic connections: ensure the connector passes a user value in the connection string.

Server migrations: after upgrades, review audit_log_format settings and confirm audit_log_user is populated. Galaxy users can enable connection diagnostics in the editor to surface empty-user sessions before they hit production.

Best Practices to Avoid This Error

Create all accounts with explicit user names, disable anonymous users, and enforce strong authentication plugins. Always test audit filters in a staging instance before applying them in production. Monitor the MySQL error log for 3221 entries and set up alerts.

Using Galaxy, engineers can version control their CREATE USER and audit filter scripts, making regressions easier to spot and roll back.

Related Errors and Solutions

ER_AUDIT_LOG_FILE_FULL raises when the audit log volume fills up. Increase disk capacity or rotate logs. ER_AUDIT_LOG_INSUFFICIENT_PRIVILEGE appears when a non-privileged user tries to change audit settings. Grant AUDIT_ADMIN or perform the action as root@localhost.

Common Causes

Empty CURRENT_USER value

Sessions created by misconfigured connectors or proxy accounts may lack a valid CURRENT_USER, leaving the audit log user field blank.

Anonymous or wildcard accounts

Legacy ''@'%' accounts allow connections without an explicit user name, producing empty values during audit serialization.

Faulty audit filter expressions

Filters that manually set user_name to '' when suppressing data can accidentally trigger the error.

Authentication plugin failures

LDAP or PAM plugins that return NULL on partial failures leave the session authenticated but without a user identifier.

Related Errors

ER_AUDIT_LOG_FILE_FULL (MySQL 3218)

Raised when the audit log partition runs out of space. Rotate or purge old logs.

ER_AUDIT_LOG_INSUFFICIENT_PRIVILEGE (MySQL 3220)

Appears when a user without AUDIT_ADMIN attempts to modify audit configurations.

ER_AUDIT_JSON_INVALID_DOCUMENT (MySQL 3222)

Occurs when the JSON audit entry violates schema rules other than user_name, such as missing command class.

FAQs

Does this error appear without the audit plugin?

No. Error 3221 is specific to the MySQL Enterprise Audit plugin when audit_log_format is set to JSON.

Will disabling anonymous users stop the error?

In most cases, yes. Removing '' accounts ensures every connection supplies a user name.

Can I bypass validation and allow empty user names?

No. The JSON schema is hard-coded. You must supply a non-empty user value or disable JSON auditing.

How does Galaxy help prevent this problem?

Galaxy surfaces connection metadata in its editor, flags sessions with blank users, and lets teams version-control audit scripts to avoid misconfigurations.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo