MySQL 8.1.0 is officially released!

As early as five years ago, MySQL 8.0 released the first GA version, and has been updating this version since then without upgrading the major version. Recently, MySQL officially released MySQL 8.1.0 and MySQL 8.0.34 , representing the innovation version and long-term support version respectively.

insert image description here

SQL-related improvements in the new version include saving execution plan output and using system functions as default values ​​for character fields .

MySQL version 8.1.0 supports saving the output of the EXPLAIN FORMAT=JSON command as a user variable, the syntax is as follows:

EXPLAIN FORMAT=JSON INTO var_name 
explainable_stmt 

The value of the variable is a JSON document that can be further processed using JSON functions such as JSON_EXTRACT().

Among them, the INTO clause only supports the FORMAT=JSON option, and the JSON format set by the system variable explain_format is invalid. If explainable_stmt fails to execute, the value of the user variable will not be updated.

The INTO clause does not support the EXPLAIN ANALYZE and EXPLAIN FOR CONNECTION statements.

For a detailed introduction to the EXPLAIN command, you can refer to the official documentation .

MySQL 8.1.0 and MySQL 8.0.34 support the use of the system functions CURRENT_USER(), SESSION_USER(), USER(), and SYSTEM_USER() as default values ​​for VARCHAR and TEXT fields. For example:

mysql> SELECT CURRENT_USER();
+-------------------+
| CURRENT_USER()    |
+-------------------+
|  sakila@localhost |
+-------------------+
1 row in set (0.00 sec)

mysql> CREATE TABLE t (
     >  c1 VARCHAR(288) DEFAULT (USER()),
     >  c2 VARCHAR(288) DEFAULT (CURRENT_USER()),
     >  c3 VARCHAR(288) DEFAULT (SESSION_USER()), 
     >  c4 VARCHAR(288) DEFAULT (SYSTEM_USER())
     > );
Query OK, 0 rows affected (0.04 sec)

mysql> INSERT INTO t VALUES ROW();
Query OK, 1 row affected (0.01 sec)

mysql> TABLE t;
+-------------------+-------------------+-------------------+-------------------+
| c1                | c2                | c3                | c4                |
+-------------------+-------------------+-------------------+-------------------+
|  sakila@localhost |  sakila@localhost |  sakila@localhost |  sakila@localhost |
+-------------------+-------------------+-------------------+-------------------+
1 row in set (0.00 sec)

If we use the SHOW CREATE TABLE and SHOW COLUMNS commands to view the table structure, we can see the functions in the definition. In addition, you can also view the default value through the COLUMN_DEFAULT field of the system table INFORMATION_SCHEMA.COLUMNS.

If you want to ensure that you can store the largest possible data length, define fields with a length of at least 288 characters (255 for username, 32 for hostname, plus an @ sign). When defining a field of CHAR type, it is not recommended to use the above system functions as default values, because it may cause errors or data loss.

For a complete update on MySQL 8.1.0, you can refer to the official release notes .

Guess you like

Origin blog.csdn.net/horses/article/details/131822708