MySQL Variables init_connect 数据库 参数变量解释及正确配置使用
本站中文解释
init_connect参数为MySQL客户端用来在和服务器建立连接时初始化客户端变量的SQL命令字符串。这样可以定义多个变量,每个客户端会话都会自动执行这些变量初始化工作,而不用每次每个客户端会话都需要重复设置变量。
设置init_connect变量的方式如下:
1.使用set命令:SET init_connect=’命令字符串’
2. 在配置文件my.cnf文件中定义init_connect变量,其值为命令字符串:
init_connect=’命令字符串’
3. 使用命令提示符,可以使用–init_connect以及其跟随的参数字符串:
mysqld –init_connect=’命令字符串’
4. 使用系统变量也可以实现相同的效果:
SET GLOBAL init_connect=’命令字符串’ ;
官方英文解释
init_connect
Command-Line Format | --init-connect=name |
---|---|
System Variable | init_connect |
Scope | Global |
Dynamic | Yes |
Type | String |
A string to be executed by the server for each client that
connects. The string consists of one or more SQL statements,
separated by semicolon characters.
For users that have the SUPER
privilege, the content of
init_connect
is not executed.
This is done so that an erroneous value for
init_connect
does not prevent
all clients from connecting. For example, the value might
contain a statement that has a syntax error, thus causing
client connections to fail. Not executing
init_connect
for users that
have the SUPER
privilege
enables them to open a connection and fix the
init_connect
value.
As of MySQL 5.7.22,
init_connect
execution is
skipped for any client user with an expired password. This is
done because such a user cannot execute arbitrary statements,
and thus init_connect
execution fails, leaving the client unable to connect.
Skipping init_connect
execution enables the user to connect and change password.
The server discards any result sets produced by statements in
the value of of init_connect
.