Databases 5 min read

Customizing MySQL 8.0 Execution Plan Output per User with the explain_format Variable

This article explains how MySQL 8.0.32 introduces the @@explain_format system variable that allows administrators to set different execution‑plan output formats (tree, traditional, json, etc.) for individual users, and demonstrates the configuration steps with concrete SQL commands and examples.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Customizing MySQL 8.0 Execution Plan Output per User with the explain_format Variable

When a client requested different execution‑plan formats for different MySQL users, the author initially suggested three work‑arounds: writing a wrapper script, using shell aliases, or doing nothing; the client chose the third option.

Fortunately, MySQL 8.0.32 adds the system variable @@explain_format , which can be set per session to control the format of the EXPLAIN output (e.g., tree , traditional , json ). The official documentation is available at the MySQL reference manual.

To demonstrate, the author first sets the default format to tree and shows the resulting output, then switches to traditional and displays the traditional column‑based format.

Next, two users are created: zhangsan (who prefers tree ) and lisi (who prefers json ). The necessary CREATE USER and GRANT SELECT statements are shown.

Each user connects to MySQL with an --init-command that sets their preferred format. For zhangsan the command is:

mysql -uzhangsan --init-command='set @@explain_format=tree' -D ytt

Running EXPLAIN TABLE t1\G then produces a tree‑style plan. The same approach is used for lisi with set @@explain_format=json , yielding a JSON‑formatted plan (output omitted for brevity).

The article concludes with a brief promotion of the SQLE tool and community resources, which are unrelated to the technical demonstration.

DatabaseMySQLexecution planexplain_formatMySQL8per-user configuration
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.