简体   繁体   中英

Which MySQL variable sets the default collate of local variable?

Say I have this stored procedure:

CREATE PROCEDURE x(
)
LANGUAGE SQL
DETERMINISTIC
MODIFIES SQL DATA
SQL SECURITY INVOKER
COMMENT ''
BEGIN

DECLARE test VARCHAR(50) CHARACTER SET 'utf8mb4';

-- ...

END

What is the mysql server variable that define the local variable test 's collation?

It currently is (thanks, mysql 8.0...) utf8mb4_0900_ai_ci so I get yield a "nice" Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation '=' in a later on code.

Setting

DECLARE test VARCHAR(50) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci';

Removes the Illegal collation error, so I'm sure it's this variable that has the bad 0900 collation.

But, no, I'm not gonna rewrite all my local variables in all my procedures to set this explicit collation. So how do I set this globally for the server? or at least, how to I set this for the connection?

So far, I have the default mysql 8 configuration besides the following:

[mysqld]
skip-log-bin
innodb_buffer_pool_size = 4G
character_set_server = utf8mb4
collation_server = utf8mb4_general_ci

# character_set_database  = utf8mb4
# collation_database = utf8mb4_general_ci
# character_set_client = utf8mb4
# character_set_connection = utf8mb4
# collation_connection = utf8mb4_general_ci
# character_set_results = utf8mb4

and this statement run at client connection:

SET CHARACTER SET utf8mb4, NAMES utf8mb4, collation_connection = 'utf8mb4_general_ci', lc_messages = 'en_US', time_zone = '+00:00'

Commented out variables are those throwing a unknown variable '...=...' when trying to start mysql server, despite these variables being listed in mysql 8 documentation tho...

From the docs :

If CHARACTER SET and COLLATE are not present, the database character set and collation in effect at routine creation time are used . To avoid having the server use the database character set and collation, provide an explicit CHARACTER SET and a COLLATE attribute for character data parameters.

Most likely, the stored procedure was created before you updated the configuration, in which case all you need to do is drop and recreate them so that they use the new defaults.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM